var file ; 
var lastIndex = 0;
var lastVideoIndex = 0;
var fadespeed = 1000 ;

function closeLightBox(light, fade){

   var fader1 = new Fx.Style(light, 'opacity', {duration:fadespeed,onComplete:dimFade});
   //fader1.set(0);
   fader1.start(0.5,0);
   //var fader = new Fx.Style(fade, 'opacity', {duration:fadespeed});
   //fader.set(0);
   //fader.start(1,0);
   //$(light).innerHTML = "" ;
   //currentthumbpos=0 ;
   
}
function dimFade(){
   var fader = new Fx.Style(fade, 'opacity', {duration:fadespeed,onComplete:emptyLight});
   //fader.set(0);
   fader.start(0.7,0);
}
function emptyLight(){
   $(light).innerHTML = "" ;
   currentthumbpos=0 ;
   if(insideOls == 'yes'){
     history.go(0);
   }  
}  

function showLightBox(light, fade){
   //alert('light box');
   document.getElementById(light).style.display='block';
   document.getElementById(fade).style.display='block' ;
   var width = screen.width ;
   var margin = (width - 800) / 2 ;
   $('light').style.left = margin ;
   //$('light').innerHTML = "<img src='uploader/images/730_icon.jpg'>" ;
   var fader = new Fx.Style(fade, 'opacity', {duration:fadespeed});
   fader.set(0);
   fader.start(0,0.7);
   var fader1 = new Fx.Style(light, 'opacity', {duration:fadespeed});
   fader1.set(0);
   fader1.start(0,1);
   window.scrollTo(0,0);
}

function getNewsImage(id , url){
        //var tempText = tempgallery[i][0] ; 
        //tempText = tempText.replace('small', 'original') ;
		$(id).innerHTML =  "<img valign='middle' src='" + url + "'>" ;
		var fader = new Fx.Style(id ,'opacity', {duration:fadespeed});
	    fader.set(0);
	    fader.start(0,1);
	    myloadedimage[url] = 1 ;
	   
	
    //alert(url);
}    

function retrieveImage(id, pic){
  pic = praseInt(pic);
  $(id).innerHTML = "<img src='" + tempgallery[2][0] + "'>" ;
  setSize(pic) ;
  setDescription(pic);
} 

function getNewsResult(url, id, firstPic ){
    new Ajax('http://www.creatlearning.net/big5/' + url, {
        method: 'get',
        onComplete: function(){
             $(id).innerHTML = this.response.text ;
           //$('news_content').innerHTML="<img src='" + firstPic + "'>" ; //uploader/images/730_icon.jpg'>" ;
            //alert(firstPic) ;
             setSize(0) ;
             getNewsImage('news_content', firstPic) ;
             currentthumbpos=0;
             thumbnailnum = tempgallery.length ;
             $(news_title_text).innerHTML = creatNewsText();
             setDescription(0) ;
        }
        }).request();
        //alert(firstPic);
        //getNewsImage('news_content', firstPic) ;
}

function startNews(url, id, firstPic){
      getNewsResult(url, id, firstPic);
      
      
      //alert(firstPic);
      
}

// set the description text
function setDescription(i){
   var text ;
   var newsheading = 'newsheading' + i ;
   text =  tempgallery[i][7] + " <div style='display:inline;font-size:12px'>&nbsp;&nbsp;(" + tempgallery[i][6] + ")</div>"; 
   $(news_description).innerHTML = text ;
   lastIndex = parseInt(i) ;
   setSize(i);
   setTextStyle(newsheading) ;
   
}
// set the style when the image is onmouseover and onmouseout
function setSelect(i){ 
  var temp = 'newsheading' + i ;
  $(temp).style.color = '#ee778b' ;
  $(temp).style.border = '2px dashed #66e247' ;
  text =  tempgallery[i][7] + " <div style='display:inline;font-size:12px'>&nbsp;&nbsp;(" + tempgallery[i][6] + ")</div>" ; 
  $(news_description).innerHTML = text ;
  
}
// disselect the style onmouseout
function unSelect(i){ 
  
  var temp = 'newsheading' + i ;
  $(temp).style.color = '#5fa6db' ;
  $(temp).style.border = 'none' ;
  temp = 'newsheading' + lastIndex ; //alert(lastIndex);
  setTextStyle(temp) ;
  setDescription(lastIndex);
 
}

// set the style for title when image select
function setTextStyle(newsheading){
    for(i=0; i<tempgallery.length ; i++){
      var temp = 'newsheading' + i ;
      $(temp).style.color = '#5fa6db' ;
      $(temp).style.border = 'none' ;
   }   
   $(newsheading).style.color = '#ee778b' ;
   $(newsheading).style.border = '1px solid red' ;
   //$(newsheading).style.fontsize = 16 ;
   //$(newsdescription).style.fontsize = 14 ;
}

// set window height according to different photo
function setSize(i){
  // alert(parseInt(tempgallery[i][2]) + 6) ;
   var expectHeight = 660 ; //parseInt(tempgallery[i][2]) + 230 ;
   var expectWidth = 900 ; // parseInt(tempgallery[i][1]) + 300 ;
   var screenHeight = screen.height ;
   var screenWidth = screen.width ;
  
   if(screenHeight < expectHeight){ 
      $('light').style.top = 0 ;
      $('light').style.height = expectHeight  ;
      $('light').style.width = expectWidth ;
      $('fade').style.height = expectHeight ;           
   }else{
      $('light').style.top = 0 ;//(screenHeight - expectHeight) /2 ;
      $('light').style.left = ((screenWidth - expectWidth) /2) ;
      $('light').style.height = expectHeight  ;
      $('light').style.width = expectWidth ;
      
   }
   $('news_content').style.width = parseInt(tempgallery[i][1]) + 6 ;
   $('news_content').style.height =parseInt(tempgallery[i][2]) + 6 ; 
}

function creatNewsText(){ 
   var returnText ;
   var i ;
   returnText = "<div id='detail'><table class='newstable'><tr align='center'><td id='newstitle' colspan='3' >新聞標題</td></tr>" ;
   for(i=0; i < tempgallery.length; i++){
        var tempText = tempgallery[i][0] ; 
        tempText = tempText.replace('small', 'original') ;
        returnText += "<tr><td id='newsheading'><div id='newsheading" + i + "'><b>" + tempgallery[i][6] + "</b><div id='newsdescription'><a href='" + tempText + "' target='_blank'>" + tempgallery[i][7] + "<b><font color='#6872f2'> .....詳細內容</b></font></a></div></div></td></tr>" ;
          
   }
   returnText += "</table></div>" ;  
   return returnText ;
}

//
// here start the function for media_video.php
//


// startVideo(url, id){
function startVideo(url, id){
   getVideoResult(url, id);
}

// Ajax request for media_video     
function getVideoResult(url, id ){
    //var videoheading = 'videoheading' + id ;
    new Ajax('http://www.creatlearning.net/big5/' + url, {
        method: 'get',
        onComplete: function(){
             $(id).innerHTML = this.response.text ;
             setVideoSize() ;
             setVideotext() ;
             $('video_text').innerHTML = creatVideoText();
             currentthumbpos= parseInt(id);
             thumbnailnum = videotempgallery.length ;
             //setVideoStyle(videoheading) ;
        }
        }).request();
        
}

function getFileUrl(url, id ){
    url = url + '?n=' + id ;
    var videoheading = 'videoheading' + id ;
    //alert(url) ;
    new Ajax(url, {
        method: 'get',
        onComplete: function(){
             mediatv.SetVariable('movieflv',this.response.text);
             mediatv.GotoFrame(1);
             mediatv.Play();
             setVideoStyle(videoheading) ;
        }
        }).request();
        
}

// set window height and width for video player
function setVideoSize(){
   var expectHeight = 660 ; // player + margin height
   var expectWidth = 830 ;  // player + margin width
   var screenHeight = screen.height ; 
   if(screenHeight < expectHeight){ 
      $('light').style.top = 0 ;
      $('light').style.height = expectHeight  ;
      $('light').style.width = expectWidth ;
      $('fade').style.height = expectHeight ;           
   }else{
      $('light').style.top = 0 ;//(screenHeight - expectHeight) /2 ;
      $('light').style.height = expectHeight  ;
      $('light').style.width = expectWidth ;
   }
}

// set the style for title when image select
function setVideoStyle(videoheading){
    for(i=0; i<videotempgallery.length ; i++){
      var temp = 'videoheading' + i ;
      $(temp).style.color = '#5fa6db' ;
      $(temp).style.border = 'none' ;
   }   
   $(videoheading).style.color = '#ee778b' ;
   $(videoheading).style.border = '1px solid red' ;
  // $(videoheading).style.fontsize = 16 ;
  // $(videodescription).style.fontsize = 14 ;
}


// set the title text for video
function setVideotext(){
   $('video_description').innerHTML = '電視新聞報導' ;
}

// creat the video text at right hand side
function creatVideoText(){ 
   var returnText ;
   var i ;
   returnText = "<table id='videotable'><tr align='center'><td id='videotitle' colspan='3' >電視報導標題</td></tr>" ;
   for(i=0; i < videotempgallery.length; i++){
        //var tempText = videotempgallery[i][0] ; 
        //tempText = tempText.replace('small', 'original') ;
        returnText += "<tr><td id='videoheading'><div id='videoheading" + i + "'><b>" + videotempgallery[i][6] + "</b><div id='videodescription'><a href='#' onclick=\"setFlv(" + i + ");\">" + videotempgallery[i][7] + "</a></div></div></td></tr>" ;
          
   }
   returnText  += "</table>" ;
   // now create the Dr.karsten info
   returnText += "<table><tr><td><div id='k_info'><div id='k_photo'><img src='http://www.creatlearning.net/big5/images/dr_karsten.jpg'></div><div id='k_title'>卓憶課程創作總監</div><div id='videodescription'><a href='http://www.creatlearning.net/big5/main.php?id=463'>Dr. Karsten<br>卡士登博士小檔案</a></div></div></td></tr></table>" ;
   
   return returnText ;
}

function setFlv(number){
   
   var url = 'media/video/getflv.php' ; //'http://www.creatlearning.net/big5/media/video/getflv.php' ;
   getFileUrl(url, number);
   lastVideoIndex = parseInt(number);
   //setVideoStyle('videoheading' + lastVideoIndex) ;
   //file = 'Dr. G. Karsten.flv';
   
}

function setVideoOver(i){
  
  var temp = 'videoheading' + i ;
  $(temp).style.color = '#ee778b' ;
  $(temp).style.border = '2px dashed #66e247' ;
  text =  videotempgallery[i][6] + " " + videotempgallery[i][7] ; 
  //$(video_description).innerHTML = text ;
  
}

function unsetVideoOver(i){
  var temp = 'videoheading' + i ;
 // $(temp).style.color = '#5fa6db' ;
 // $(temp).style.border = 'none' ;
  temp = 'videoheading' + lastVideoIndex ;
  //alert('lastVideoIndex ' + lastVideoIndex) ;
  setVideoStyle(temp) ;
  //setDescription(lastIndex);
 
}

//////////////////////////////
// function for pop up video box on menu.swf
//////////////////////////////

function startSmallVideo(){
    var result_text = '' ;
    result_text += "<div id='small_video_middle'></div>" ;
    $('light').style.width = 560 ;
    $('light').style.height = 460 ;
    $('light').style.top = 50 ;
    $('light').style.left = ((screen.width - 520) /2) ;
    $('light').innerHTML = result_text ;
    var so = new SWFObject("small_video.swf", "small_video_middle", "520", "420", "9", "#ffffff");
	    so.addParam("wmode","transparent");so.write("small_video_middle");
}

    
//////////////////////////////////////////////////
// function for pop up testimonial photo album  
//////////////////////////////////////////////////

function startTestimonial(){
   showLightBox('light','fade');
   var result_text = '' ;
   result_text += "<div id='Testimonial'></div>" ;
   $('light').style.width = 806 ;
   $('light').style.height = 606;
   $('light').style.top = 10 ;
   $('light').style.left = ((screen.width - 806) /2) ;
   $('light').innerHTML = result_text ;
   //var so = new SWFObject("http://www.creatlearning.net/big5/testimonial/Testimonial.swf","Testimonial", "800", "600", "9", "#ffffff");
    var so = new SWFObject('flashpreloader.swf','Testimonial','800','600','9','#ffffff');
    so.addVariable("creatlearning", 'n43485430');	
	so.write("Testimonial");
}        
    
      
      