﻿//puts effects onto menu using jquery library - jquery.com.
// execute as soon as the necessary DOM is loaded
$(document).ready(function() {  
        //hide the roles go button
        $("input.go").hide();        
       //change the width of select box to 184px
        $("#leftnav").find("select").css({width: "184px"}); 
       //and bind an onclick event to each option to navigate when selected
	   $("#leftnav").find("select").bind("change",navigateToSelectedOption);       
     
       //hide the sub menu
        $("ul.animate").hide();
        
        //is it a role directory?
        if ($("body").attr("class")=="policeofficers" || $("body").attr("class")=="communicationsops" || $("body").attr("class")=="communitysupport" || $("body").attr("class")=="specialconstables" || $("body").attr("class")=="policestaff" || $("body").attr("class")=="transferees" || $("body").attr("class")=="volunteers")
        {
            //position the menu elements below absolutely so they don't scroll down too when subnav opens up
            //find the height of the animated div, add height to the top of page and force block below down (done as sections have different heights)
            var intPosition = $("ul.animate").height() + 165 + "px";
            $("div.othernav").css({position: "absolute", top: intPosition}); 
            
        //fix IE 6 problem with dynamic menu dropping below wrapper     
        if($.browser.msie && navigator.userAgent.indexOf("MSIE 6")!=-1)
        {//add the extra height back into the wrapper
            var strWrapperheight = $("#wrapper").height() + $("div.othernav").height() + "px";
            $("#wrapper").height(strWrapperheight)     ;     
        }        
        //animate the subnav
	   // $("ul.animate").fadeIn(2000);
	   $("ul.animate").slideDown(2000);	   
	   }	  
	   //bind all anchors in menu to a background fade function
	   $("#leftnav").find("a").bind("mouseover",addFade);
	  
	   addAnalyticsTrackingForExternalLinks() 

	   
});

// add analytics for outbound links (eg ATS)
function addAnalyticsTrackingForExternalLinks()
{
   $("a[@target=_blank]").click(function(){        
        pageTracker._trackPageview('/outgoing/'+ $(this).attr('href'))
          
    });
}


//functions for fade effect
function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}


function doBGFade(elem,startRGB,endRGB,finalColor,steps,intervals,powr) {
	if (elem.bgFadeInt) window.clearInterval(elem.bgFadeInt);
	var actStep = 0;
	elem.bgFadeInt = window.setInterval(
		function() {
			elem.style.backgroundColor = "rgb("+
				easeInOut(startRGB[0],endRGB[0],steps,actStep,powr)+","+
				easeInOut(startRGB[1],endRGB[1],steps,actStep,powr)+","+
				easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)+")";
			actStep++;
			if (actStep > steps) {
			elem.style.backgroundColor = finalColor;
			window.clearInterval(elem.bgFadeInt);
			}
		}
		,intervals)
}
//addFade is defined in the master page cs (so we can utilise different colours)

function navigateToSelectedOption()
//left nav menu navigation - go to selected option
{
    if($(this).val() != "default")
    {
     window.location= ("/roles/" + $(this).val() + "/default.aspx")
    }
}



function cycleProfileStills()

{//for homepage profile image cycling

//only call slideshow if Flash isn't already playing
if ($("object || embed").size()==0 && ($("div[@id$='htmlpanel_video']").size()==0))
{
$(".transcriptbuttonflash").hide();
    $('#video').cycle({ 
        fx:      'scrollLeft', 
        speedIn:  1000, 
        speedOut: 1000, 
        delay:   1000, 
        autostop: 4
    });
    }
    //only trigger script when in flash mode
     if($("div[@id$='htmlpanel_video']").size()==0)
     {
     // hook up click actions to load flash, disable slideshow and show/hide transcript
$("#profilescalltoaction, #video").click(function(){
    loadSWFObject();
    //let Google Analytics know a video has been loaded
    pageTracker._trackPageview("/flash/video/homepage");
  
   $("#profilescalltoaction").text("");
    $('#video').cycle("stop");
    $(".transcriptbuttonflash").show()
    $(".transcriptbuttonflash").toggle(
        function(){
            $(".transcript").show("slow")
            $(".transcriptbuttonflash").attr("src","images/transcript_policeofficer_minus.png")
            $(".transcriptbuttonclose").click(function(){
                    $(".transcript").hide() 
            });
            
        }, 
        function(){
            $(".transcript").hide("slow") 
            $(".transcriptbuttonflash").attr("src","images/transcript_policeofficer_plus.png")       
        });
  
           
    
});
    }
}
