/* home slider */
$(document).ready(function(){
	$('#homeSlider').append('<div class="sliderBlackBar"></div><div class="dotsBar"></div><div class="arrowLeft"></div><div class="arrowRight"></div>');
	$('#homeSlider .sliderBlackBar').css({ display:'block',opacity:0});
	$('#homeSlider li').each(function(){
		$(this).css({ display:'block',opacity:0});
		$('#homeSlider .dotsBar').append('<div class="dotDiv"></div>');
	});
	$('#homeSlider .dotDiv').click(function(){
		clearInterval(homeSliderInterval);
		$('#homeSlider .dotDiv').css({opacity:1});
		$('#homeSlider li').eq(currentHomeSlider).animate({opacity:0,'z-index':0},600);
		currentHomeSlider=$('#homeSlider .dotDiv').index($(this));
		$('#homeSlider li').eq(currentHomeSlider).animate({opacity:1,'z-index':1},600);
		$('#homeSlider .sliderBlackBar').animate({opacity:0},600,function(){
			$('#homeSlider .sliderBlackBar').html($('#homeSlider li div').eq(currentHomeSlider).html());
			$('#homeSlider .sliderBlackBar').animate({opacity:1},600);
			$('#homeSlider .dotDiv').eq(currentHomeSlider).css({opacity:0.5});
		});
	});
	currentHomeSlider=0;
	totalImagesHomeSlider=$('#homeSlider li').length-1;
	homeSliderInterval=setInterval(function(){
		$('#homeSlider .dotDiv').css({opacity:1});
		$('#homeSlider li').eq(currentHomeSlider).animate({opacity:0,'z-index':0},600);
		currentHomeSlider++;
		if(currentHomeSlider>totalImagesHomeSlider)
			currentHomeSlider=0;
		$('#homeSlider li').eq(currentHomeSlider).animate({opacity:1,'z-index':1},600);
		$('#homeSlider .sliderBlackBar').animate({opacity:0},600,function(){
			$('#homeSlider .sliderBlackBar').html($('#homeSlider li div').eq(currentHomeSlider).html());
			$('#homeSlider .dotDiv').eq(currentHomeSlider).css({opacity:0.5});
			$('#homeSlider .sliderBlackBar').animate({opacity:1},600);
		});
	},8000);
	//left and right arrows
	$('#homeSlider .arrowLeft').click(function(){
		tmpCurrentHomeSlider=currentHomeSlider;
		tmpCurrentHomeSlider--;
		if(tmpCurrentHomeSlider<0)
			tmpCurrentHomeSlider=totalImagesHomeSlider;
		$('#homeSlider .dotDiv').eq(tmpCurrentHomeSlider).trigger('click');
	});
	$('#homeSlider .arrowRight').click(function(){
		tmpCurrentHomeSlider=currentHomeSlider;
		tmpCurrentHomeSlider++;
		if(tmpCurrentHomeSlider>totalImagesHomeSlider)
			tmpCurrentHomeSlider=0;
		$('#homeSlider .dotDiv').eq(tmpCurrentHomeSlider).trigger('click');
	});
	//slider initialize
	$('#homeSlider .dotDiv').eq(0).css({opacity:0.5});
	$('#homeSlider .sliderBlackBar').html($('#homeSlider li div').eq(0).html());
	$('#homeSlider .sliderBlackBar').animate({opacity:1},600);
	$('#homeSlider li').eq(0).animate({opacity:1,'z-index':1});
	//green boxes click function
	$('.boxGreen').click(function(){
		tempIndex=$('.boxGreen').index($(this));
		document.location=$('a.greenButton').eq(tempIndex).attr('href');
	});
	
	//overlay code
	//overlay
	$('body').append('<div id="teraCustomDialog" style="display:none"></div><div id="teraOverlay"></div><div id="teraCloseButton"></div>');
	$('#teraOverlay,#teraCloseButton').click(function(){
		$('#teraCloseButton').animate({opacity:0},600);
		$('#teraCustomDialog').animate({opacity:0},600,function(){
			$('#teraOverlay').animate({opacity:0},600,function(){
				$('#teraCustomDialog div:first').scrollTop(0);
				$('#teraOverlay, #teraCustomDialog,#teraCloseButton').css({display:'none'});
			});
		});
	});
	$('.teraCommBoxLink').click(function(){
		teraHeight=$('#teraCommBox').height()+10;
		if(teraHeight>540)
			teraHeight=600;
		else
			teraHeight+=190;
		$('#teraCustomDialog').html('');
		$('#teraCustomDialog').append('<div style="position:relative; height:600px; overflow-y:auto; width:390px; padding-right:10px;">'+$('#teraCommBox').html()+'<div style="clear:both;"></div>'+'</div>');
		
		$('#teraCustomDialog div:first').css({height:teraHeight-10});
		$('#teraOverlay').css({width:$(window).width(),height:$(window).height(),'z-index':1000,position:'fixed',background:'#000',left:0, top:0,opacity:0,display:'block'});
		$('#teraOverlay').animate({opacity:0.7},600,function(){					
			leftPos=($(window).width()-400)/2;
			$('#teraCustomDialog').css({display:'block'});
			topPos=(($(window).height()-teraHeight)/2)-10;
			$('#teraCloseButton').css({position:'fixed','z-index':1002,left:leftPos+393,opacity:0,top:topPos-20,display:'block'});
			$('#teraCustomDialog').css({'text-align':'left',position:'fixed','z-index':1001,width:400,height:teraHeight,padding:'13px 0px 13px 13px',background:'#FFF', border:'2px solid #090','border-radius':8,left:leftPos,top:topPos,opacity:0});
			$('#teraCustomDialog').animate({opacity:1},600);
			$('#teraCloseButton').animate({opacity:1},600);
		});				
	});
	
});
