$(document).ready(function(){	
	if ($('.rotateCopy').html() != null){
		rotateImg();
		//rotateImg_paging();
		$('.slide-page').bind('click', rotateImg_paging);
		$('.slide-nextpage').bind('click', rotateImg_next);
		$('.slide-prevpage').bind('click', rotateImg_prev);
	}
});

var delayRotate = 5000;
var animationSpeed = 2000;
var tempRotateI = 0;
var count_lastest;
var subBanner;
function rotateImg(paging){	
	count_lastest = $('.rotateCopy').length;		
	
	if (paging=='prev') {tempRotateI = tempRotateI+1; if (tempRotateI == count_lastest) tempRotateI=0; }
	
	rotatingImg();
	
	if (count_lastest>1) subBanner=setTimeout("rotateImg()",delayRotate)
	/*switch(paging)
	{
		case 'prev':*/
		tempRotateI = tempRotateI+1;
		if (tempRotateI == count_lastest) tempRotateI=0;	
};


function rotateImg_paging(){	
	$('.slide-page').unbind('click', rotateImg_paging);
	$('.slide-pagination .slide-page').removeClass('slide-selected');
	$(this).addClass('slide-selected');
								  
	if (subBanner) clearTimeout(subBanner);
	tempRotateI = parseInt($(this).html())-1;
	rotateImg();
}

function rotatingImg(){	
	$('.slide-pagination .slide-page').removeClass('slide-selected');	
	$('.slide-pagination .slide-page:eq('+tempRotateI+')').addClass('slide-selected');	
	
	// fading effect
	$('.rotateCopy').fadeOut(animationSpeed);
	$('.rotateCopy:eq('+tempRotateI+')').fadeIn(animationSpeed, function(){
		$('.slide-page').bind('click', rotateImg_paging);
		$('.slide-nextpage').bind('click', rotateImg_next);
		$('.slide-prevpage').bind('click', rotateImg_prev);
		animationSpeed = 2000;
	});
}

function rotateImg_next(){
	animationSpeed = 0;
	$('.slide-nextpage').unbind('click', rotateImg_next);
								  
	if (subBanner) clearTimeout(subBanner);
	
	rotatingImg();
	
	tempRotateI = tempRotateI+1;
	if (tempRotateI == count_lastest) tempRotateI=0;	
	
	subBanner=setTimeout("rotateImg('next')",delayRotate);
}

function rotateImg_prev(){
	animationSpeed = 0;
	$('.slide-prevpage').unbind('click', rotateImg_prev);	
								  
	if (subBanner) clearTimeout(subBanner);
	
	tempRotateI = tempRotateI-1;
	if (tempRotateI<0) { tempRotateI=count_lastest-1; }

	rotatingImg();
	
	subBanner=setTimeout("rotateImg('prev')",delayRotate);
}


// @param int val 	0: pageWidth, 1: pageHeight, 2: windowWidth, 3: windowHeight
function getDocumentSize(val){
	var xScroll,yScroll,value;
	if(window.innerHeight&&window.scrollMaxY)	{
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight)	{
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}
	else{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	
	var windowWidth,windowHeight;	
	if(self.innerHeight){
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight){
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	else if(document.body){
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}

	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}

	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}

	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight)	
	return arrayPageSize[val]
}// end function

