
$jq(document).ready(function(){
	var strButtonText="";
	var blnNivoStopped = true;
	sma_StartSlider();
	sma_SetHovering();
	sma_SelectActivePersona();
	sma_evtMouseMove();
});
/*Start -- start NivoSlider */
function sma_StartSlider() {
	var slide = sma_GetCurrentPersona();
	
	$jq('#slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
        slices:6,
        animSpeed:300, //Slide transition speed
        pauseTime:6000,
        startSlide:slide, //Set starting Slide (0 index)
        directionNav:false, //Next & Prev
        directionNavHide:false, //Only show on hover
        controlNav:false, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:false, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
		afterChange: sma_NivoAfterChange,
        beforeChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
        lastSlide: function(){}, //Triggers when last slide is shown
        afterLoad: function(){} //Triggers when slider has loaded
	});
	sma_NivoAfterChange();
	blnNivoStopped = false;
}
function sma_NivoAfterChange(){
			var intSlide = $jq('#slider').data('nivo:vars').currentSlide+1;


			$jq("#TopMenuContainer li").each(
				function(){
					$jq(".hpBackLava").remove();
				}
			); 
			var objTopID = $jq("#TM" + intSlide);

			if(!objTopID.attr("class")){
				objTopID = $jq("#TM" + intSlide + "_on");
			}
			if(objTopID){
				//objTopID.attr("class","TM_" + intSlide + "_on");
				var intTop = objTopID.position().top;
				var intLeft = objTopID.position().left;
				
				
				$jq("<div class='hpBackLava' style='top:"+ intTop + "px;left:" + intLeft +"px'></div>").insertAfter(objTopID);
				smaLavaHover();
			}
}
/*End -- start NivoSlider */
/*Start -- triggers Hovering for TopMenu */
function smaLavaHover(){
	$jq(".hpBackLava").hover(
		function(){
			$jq(".hpBackLava").remove();
		},
		function(){}
	);
}
function sma_SetHovering(){
	$jq("#TopMenuContainer li").hover(
		function(){
			$jq("#TopMenuContainer li").each(
				function(){
					$jq(".hpBackLava").remove();
					var newCls = $jq(this).attr("class");
					if(newCls.indexOf("_on") != -1)
					{
						$jq(this).attr("class", newCls.replace("_on", "_off"));
					}
				}
			); 	

			var newCls = $jq(this).attr("class").replace("_off","_on");
			$jq(this).attr("class",newCls);
			blnNivoStopped = true;
			sma_HideShowImage("","off");
			sma_HideShowImage(sma_GetHoveredPersona(),"on");

			$jq('#slider').data('nivoslider').stop();
		},
		function(){
			blnNivoStopped = true;
		}
	); 
}
/*End -- triggers Hovering for TopMenu */
/*Start -- Helper Functions for NivoSlider and TopMenu */
function sma_GetCurrentPersona(){
	var intIdx = -1;
	$jq("#TopMenuContainer li").each(
		function(){
			var newCls = $jq(this).attr("id");
			if(newCls.indexOf("_on") != -1)
			{
				intIdx = newCls.replace("_on", "");
				intIdx = intIdx.replace("TM", "");
				intIdx = intIdx-1;
			}
		}
	);
	return intIdx;
}
function sma_GetHoveredPersona(){
	var intIdx = -1;
	$jq("#TopMenuContainer li").each(
		function(){
			var newCls = $jq(this).attr("class");
			if(newCls.indexOf("_on") != -1)
			{
				intIdx = $jq(this).attr("class").replace("_on", "").replace("TM_", "");
			}
		}
	);
	return intIdx;
}
function sma_HideShowImage(strImage, strSwitch){
	
	var strName  = "Stage" + strImage;
	var objImg = $jq("#" + strName);
	var objImg2 = $jq("#" + strName + " a");

	if(strSwitch == "on"){
		objImg.parent("a").attr('style', 'display:block;z-index:100;');
		objImg.attr('style', 'display:block;z-index:100;');
	}
	if(strSwitch == "off"){
	$jq("#slider").each(

		function(){
			$jq(this).children().attr('style', 'display:none;z-index:0;');
		}
	);
	}
}
function sma_SelectActivePersona(){
	$jq("#TopMenuContainer li").each(
		function(){
			var newCls = $jq(this).attr("class");
			if(newCls.indexOf("_on") != -1)
			{
				$jq(this).attr("class", newCls.replace("_on", "_off"));
			}
			newCls = $jq(this).attr("id");
			if(newCls.indexOf("_on") != -1)
			{
				strButtonText = $jq("a",this).html();
				$jq(this).attr("class", $jq(this).attr("class").replace("_on", "_off"));
			}
		}
	); 
}
/*End -- Helper Functions for NivoSlider and TopMenu */
function sma_evtMouseMove(){
   $jq(document).mousemove(function(e){
		if(blnNivoStopped == true){
			var intPageLeft = $jq("#WrapperHP").position().left+20;
			var intPageRight = intPageLeft+960;
			var intPageTop = $jq("#MidContentMenuConHP").position().top;
			var intPageBottom = intPageTop+$jq("#MidContentHP").height()+$jq("#MidContentHP").height();
			
			var intPosX = e.pageX;
			var intPosY = e.pageY;
			var blnHOk = false;
			var blnVOk = false;
			var strResult = "width: " + intPageLeft + ", " + intPageRight + "height: " + intPageTop + ", " + intPageBottom + "<br/>";
			strResult += "xpos: " + e.pageX + "ypos: " + intPosY  + "<br/>";
			if(intPosX < intPageLeft || intPosX > intPageRight){
				blnHOk = true;
			}
			if(intPosY < intPageTop || intPosY > intPageBottom){
				blnVOk = true;
			}
			if(blnHOk == false && blnVOk == false){
				
			}
			else{
				blnNivoStopped = false;
				sma_SelectActivePersona();
				sma_HideShowImage("","off");
				$jq('#slider').data('nivoslider').start();
				sma_NivoAfterChange();
			}
			strResult += blnHOk + " " + blnVOk  + "<br/>";
			//$jq("#helper").html(strResult);
		}
   }); 
}
