/*
Title:     		Home
Desc:			homepage panels animation
Author:     	Mark Croxton, mcroxton@hallmark-design.co.uk
Copyright:		Hallmark Design
Created:    	April 04 2008
Updated:    	Sept 08 2008
*/
var trfa=0;
var trsa=0;
$(document).ready(function() {
	if (document.getElementById("home")) {

	// colour fades
		$('#entrance ul a').each(
			function (i) {
				$(this).html( $(this).html() + '<span></span>');
			
				//set opacity to 0
				$(this).children('span').fadeTo(1,0,'');

				$(this).hover(
					function() { //mouseover	
						$(this).children('span').css({
							visibility: 'visible'
						});
						$(this).children('span').fadeTo("normal",1,'');
					},
					function() { //mouseout
						$(this).children('span').fadeTo("slow",0,'');
					}
				);
			
			}
		);

	//slide horizontal

		//append controls
		 $('#contents').append('<div id="controls"><a id="btnLeft" href="#"><em>&lt;</em></a> <a id="btnRight" href="#"><em>&gt;</em></a></div><div id="shadowLeft"></div><div id="shadowRight"></div>');
	
	  	var $masked = $('#entrance ul');
		var $controls = $('#controls');
		var $btnLeft = $('#btnLeft');
		var $btnRight = $('#btnRight');
		var $shadowLeft = $('#shadowLeft');
		var $shadowRight = $('#shadowRight');
	
	
		// get number of panels
		var panelCount = $masked.children('li').size();
	
		// hide shadow
		$shadowLeft.css({
			visibility: 'hidden'
		});
		
		$shadowRight.css({
			visibility: 'hidden'
		});
		
		// can't vary opacity of transparent pngs in IE 6/7
		if (!$.browser.msie) {
			$shadowLeft.fadeTo(1,0,'');
			$shadowRight.fadeTo(1,0,'');
		}

		// set up some constants with global scope
		maskWidth = (parseInt($masked.children('li').css('width'))+1) * 3;
		
		totalWidth = (parseInt($masked.children('li').css('width'))+1) * panelCount;
		speed = 160*panelCount;
		inMotion = false;
	
		// set width of the ul
		$masked.css({ width: totalWidth});
	
		// set initial button state

		// slide left
	  	$btnLeft.click(function() {	
			
			var maskX = parseInt($masked.css('left'));
			if (maskX > (maskWidth - totalWidth) && !inMotion ) {
				
				inMotion = true;
				if ((maskX-maskWidth + totalWidth) < maskWidth) {
					
	   				$masked.animate({
						left: (maskWidth-totalWidth)
						},speed,'easeOutBack',manageControls, false);  
				} else {
					trsa=1;
					$masked.animate({
						left: (maskX -maskWidth)
						},speed,'easeOutBack',manageControls, false);
				}
			}else{
				trfa=1;
				$masked.css({
			left: 1000
		});
					$masked.animate({		
						left: (0)
						},speed,'easeOutBack',manageControls, false);
			}
			return false;
	 	});

		//shadow
		$btnLeft.hover(
			function(){
				$shadowLeft.css({
					visibility: 'visible'
				});
				if (!$.browser.msie) {
					$shadowLeft.fadeTo("normal",1,'');
				}
			},
			function(){
				if (!$.browser.msie) {
					$shadowLeft.fadeTo("normal",0,'');
				} else {
					$shadowLeft.css({
						visibility: 'visible'
					});
				}
			}
		);
	
		$btnRight.hover(
			function(){
				$shadowRight.css({
					visibility: 'visible'
				});
				if (!$.browser.msie) {
					$shadowRight.fadeTo("normal",1,'');
				}
			},
			function(){
				if (!$.browser.msie) {
					$shadowRight.fadeTo("normal",0,'');
				} else {
					$shadowRight.css({
						visibility: 'visible'
					});
					
				}
			}
		);

		// slide right
	  	$btnRight.click(function() {
								
			var maskX = parseInt($masked.css('left'));
			if (maskX < 0 && !inMotion ) {
				
				inMotion = true;
				if (maskX + maskWidth >0) {
	   				$masked.animate({
						left: 0
						},speed,'easeOutBack',manageControls, false);  
					
				} else {	
				trfa=1;
					$masked.animate({
						left: (maskX + maskWidth)
						},speed,'easeOutBack',manageControls, false);
				}
			}else{
					if(trfa==1){
				if ((maskX-maskWidth + totalWidth) < maskWidth) {
					
	   				$masked.animate({
						left: (maskWidth-totalWidth)
						},speed,'easeOutBack',manageControls, false);  
				} else {
					$masked.css({
			left: -2000
		});
					$masked.animate({
						left: (-777)
						},speed,'easeOutBack',manageControls, false);
					
				}
			}
			}
		
	   		return false;
	 	});

		manageControls =  function() {
			inMotion = false;
			if (panelCount>3) {
				var maskX = parseInt($masked.css('left'));
				if (maskX==0) {
					$btnLeft.css({ visibility: 'visible' });
					$btnRight.css({ visibility: 'visible' });
					if ($.browser.msie) {
						$shadowRight.css({ visibility: 'visible' });
					}
				} else if (maskX+totalWidth- maskWidth == 0) {
					$btnLeft.css({ visibility: 'visible' });
					$btnRight.css({ visibility: 'visible' });
					if ($.browser.msie) {
						$shadowLeft.css({ visibility: 'visible' });
					}
				} else {
					$btnLeft.css({ visibility: 'visible' });
					$btnRight.css({ visibility: 'visible' });
				}
			} else {
				$btnLeft.css({ visibility: 'hidden' });
				$btnRight.css({ visibility: 'hidden' });
			}
		}
		// set up initial controls state
		manageControls();
	}
	
});




function wangluo(){
document.getElementById("wl").style.background="#c8ced3";
document.getElementById("mc").style.background="none";
document.getElementById("lrjs").style.display="none";
var titab=document.getElementById("box_linkpro");
if(titab!=null){
document.getElementById("box_linkpro").style.display="none";
showMsg('box_linkpro');
}

document.getElementById("jxwl").style.display="";
document.getElementById("contents").style.height=document.getElementById("jxwl").style.height;
showMsg('contentleft');
showMsg('contentimg');

  
}
function minchen(){

document.getElementById("wl").style.background="none";
document.getElementById("mc").style.background="#c8ced3";
document.getElementById("lrjs").style.display="";
var titab=document.getElementById("box_linkpro");
if(titab!=null){
document.getElementById("box_linkpro").style.display="";
showMsg2('box_linkpro');
}

document.getElementById("jxwl").style.display="none";
document.getElementById("contents").style.height=document.getElementById("lrjs").style.height;
  showMsg2('contentleft');
showMsg2('contentimg');

	

}


 //设置透明度
function setOpacity(obj,value){
    if(document.all){
        if(value == 100){
            obj.style.filter = "";
        }else{
            obj.style.filter = "alpha(opacity=" + value + ")";    
        }
		
    }else{
        obj.style.opacity =value / 100 ;
       
    }
}
//用setTimeout循环减少透明度
function changeOpacity(obj,startValue,endValue,step,speed){
    if(step >= 0 && startValue <= endValue || step <= 0 && startValue >= endValue){
	document.getElementById("contentimg").style.display="none";
	document.getElementById("contentleft").style.display="none";
	var titab=document.getElementById("box_linkpro");
if(titab!=null){
document.getElementById("box_linkpro").style.display="none";
}

    return;
    }
    if(!obj)
    {
      return;
    }
    if(startValue<=0)
    {
      document.body.removeChild(obj);
      return;
    }
    setOpacity(obj,startValue);
    setTimeout(function(){changeOpacity(obj,startValue-step,endValue,step,speed);},speed);
}
//设置隐藏速度和id
function showMsg(id){
    var msg =document.getElementById(id);
    var step = 10, speed = 30;
    changeOpacity(msg, 100, 0, step, speed);
}

function setOpacity2(obj2, value2){
    if(document.all){
        if(value2 == 0){
            obj2.style.filter = "";
        }else{
		
            obj2.style.filter = "alpha(opacity=" + value2 + ")";   
document.getElementById("contentleft").style.display="";
document.getElementById("contentimg").style.display="";
	var titab=document.getElementById("box_linkpro");
if(titab!=null){
document.getElementById("box_linkpro").style.display="";
}

        }
	
    }else{

        obj2.style.opacity =value2 / 100 ;
       
    }
}

function showMsg2(id){
    var msg2 =document.getElementById(id);
    var step2 = 10, speed2 = 30;
    changeOpacity2(msg2, 0, 110, step2, speed2);
}

function changeOpacity2(obj2, startValue2, endValue2, step2, speed2){

    if(step2 >= 0 && startValue2 >= endValue2 || step2 >= 0 && startValue2 >= endValue2){
	document.getElementById("contentimg").style.display="";
	document.getElementById("contentleft").style.display="";
		var titab=document.getElementById("box_linkpro");
if(titab!=null){
document.getElementById("box_linkpro").style.display="";
 document.getElementById("box_linkpro").style.filter = "alpha(opacity='100')";
}
	
	document.getElementById("contentleft").style.filter = "alpha(opacity='100')";
    document.getElementById("contentimg").style.filter = "alpha(opacity='100')";
        return;
    }
    if(!obj2)
    {
	
      return;
    }
    if(startValue2>=110)
    {
	
      document.body.removeChild(obj2);
      return;
    }
    setOpacity2(obj2, startValue2);
    setTimeout(function(){changeOpacity2(obj2, startValue2+step2, endValue2, step2, speed2);}, speed2);
}


