// JavaScript Document
// JavaScript for 'global journal portals' 
// Editor:hyy,10.27.2011


//Common Pages changetab JavaScript
function oId(){
	var oIds=['change_tab'];
	for(a=0;a<oIds.length;a++){
		document.getElementById(oIds[a]).onmousemove=function(){
			ocl(this);	
		}
	}
}
function ocl(x){
	var oAs=x.getElementsByTagName('span');
	var oDivs=x.getElementsByTagName('div');
	for(var j=0;j<oAs.length;j++){
		oAs[j].index=j;
		oAs[j].onclick=function(){
			changeTab(this.index,oAs,oDivs)	
		}
	}	
}
function changeTab(nIndex,oAs,oDivs){
	
	for(i=0;i<oAs.length;i++){
		oAs[i].className='';
		oDivs[i].className='';
	}
		oAs[nIndex].className='show_tab_a';
		oDivs[nIndex].className='show_tab_div';
}
window.onload=function(){
	oId()
}

//index banner
var timer = null;
var offset = 8000;
var index = 0;
var target = ["ban_big01","ban_big02","ban_big03","ban_big04"];

//big pic change
function slideImage(i){
    var id = 'image_'+ target[i];
    $('#'+ id)
        .animate({opacity: 1}, 800, function(){
            $(this).find('.word').animate({height: 'show'}, 'slow');
        }).show()
        .siblings(':visible')
        .find('.word').animate({height: 'hide'},'fast',function(){
            $(this).parent().animate({opacity: 0}, 800).hide();
        });
}
//bind thumb a
function hookThumb(){    
    $('#thumbs li a')
        .bind('click', function(){
            if (timer) {
                clearTimeout(timer);
            }                
            var id = this.id;            
            index = getIndex(id.substr(6));
            rechange(index);
            slideImage(index); 
            timer = window.setTimeout(auto, offset);  
            this.blur();            
            return false;
        });
}
//bind next/prev img
function hookBtn(){
    $('#thumbs li img').filter('#play_prev,#play_next')
        .bind('click', function(){
            if (timer){
                clearTimeout(timer);
            }
            var id = this.id;
            if (id == 'play_prev') {
                index--;
                if (index < 0) index = 3;
            }else{
                index++;
                if (index > 3) index = 0;
            }
            rechange(index);
            slideImage(index);
            timer = window.setTimeout(auto, offset);
        });
}

function bighookBtn(){
    $('#bigpicarea p span').filter('#big_play_prev,#big_play_next')
        .bind('click', function(){
            if (timer){
                clearTimeout(timer);
            }
            var id = this.id;
            if (id == 'big_play_prev') {
                index--;
                if (index < 0) index = 3;
            }else{
                index++;
                if (index > 3) index = 0;
            }
            rechange(index);
            slideImage(index);
            timer = window.setTimeout(auto, offset);
        });
}

//get index
function getIndex(v){
    for(var i=0; i < target.length; i++){
        if (target[i] == v) return i;
    }
}
function rechange(loop){
    var id = 'thumb_'+ target[loop];
    $('#thumbs li a.current').removeClass('current');
    $('#'+ id).addClass('current');
}
function auto(){
    index++;
    if (index > 3){
        index = 0;
    }
    rechange(index);
    slideImage(index);
    timer = window.setTimeout(auto, offset);
}
$(function(){    
    //change opacity
    $('div.word').css({opacity: 0.85});
    auto();  
    hookThumb(); 
    hookBtn();
	bighookBtn()
    
});


//index pic scroll
$(function(){
    var page = 1;
    var i =7;
	$("a.next").click(function(){
		 var $parent = $(this).parents("div.list_scroll");
		 var $v_show = $parent.find("div.scroll_ul"); 
		 var $v_content = $parent.find("div.scroll_content");
		 var v_width = 125.5*i ;
		 var len = $v_show.find("li").length;
		 var page_count = Math.ceil(len / i) -1;		
		 if(page_count>=1){		 
		 if( !$v_show.is(":animated") ){
		  if( page == page_count ){
		$v_show.animate({ left : '0px'}, "slow");
		page = 1;
		return;
		}else{
		$v_show.animate({ left : '-='+v_width }, "slow");
		page++;
		 }
		 }
		 }else{
		return; 
		 } 
   });
		$("a.prev").click(function(){
	 var $parent = $(this).parents("div.list_scroll");
	 var $v_show = $parent.find("div.scroll_ul"); 
	 var $v_content = $parent.find("div.scroll_content");
	 var v_width = 125.5*i;
	 var len = $v_show.find("li").length;
	 var page_count = Math.ceil(len / i)-1 ;	
	 if( !$v_show.is(":animated") ){		
	   if( page == 1 ){
	$v_show.animate({ left : '-='+v_width*(page_count-1) }, "slow");
	page = page_count;
	}else{
	$v_show.animate({ left : '+='+v_width }, "slow");
	page--;
	}
	}
	});
});

