﻿// JavaScript Document

$(document).ready(function(){
var navp = naviPopup();
	
	
	
	
	// build carousel
	var car = new carousell();

	// build newsTicker
	var nt =  newsTicker();
	
	
	
	// bind the opener scripts for the navigation
	
	$("#subNav a").each(function (){
		if($(this).attr("id") != "popupOpener"){				  
			$(this).hover(closePopup, null);
		}
	});
	
	$("#popupOpener").hover(openPopup, null);
	
	
});

function openPopup(){
	var target = $("#naviPopup");
	target.slideDown();
	target.hover(null,closePopup);
}

function handleSelect(target){
	
	if($(target, 'option:selected').attr('value') != ""){
		//location.href=$(target, 'option:selected').attr('value');
		window.open($(target, 'option:selected').attr('value'), 'newWindow');
	}
}


function closePopup(){
	 $("#naviPopup").slideUp();
}


function createBrandBoxGoogleTrackings(){
  
  function googleAction(){
	    try{
		   pageTracker._trackEvent('BRANDBOX', 'Click', $(this).attr("href"));
		}catch(err){
					
		}
  }
  
  $(".brandBoxLinkContainer a").each(
		function(){
			var target = $(this);
			target.click(googleAction);
		});
    $(".brandBoxOverayContentItem a").each(
		function(){
			var target = $(this);
			target.click(googleAction);
		});
}


function carousell(){
	var imageLength = 90;
	var startX = 40;
	
	$(".carousellLeft").click(showPrevImage);
	
	$(".carousellRight").click(showNextImage);
	
	
	
	//number the imagesCount
	var counter = 1;
	var imagesCount = 0;
	$(".carousellImagesListItem").each(function(){
		var target = $(this);
		target.attr("itemid", counter);
		
		counter++;
		imagesCount++;
	});
	
	
	//number the link
	var counter = 1;
	$(".carousellCenter").each(function(){
		var target = $(this);
		target.attr("itemid", counter);
		
		counter++;
	});
	
	
	// set the container width to match the images
	$(".carousellImagesScroller").css("width", (imagesCount*imageLength) +"px");
	
	var currentImage = 0;
	var prevImage = 0;
	
	function showImage(itemid){
		
		
		$('.carousellCenter[itemid="'+ prevImage + '"]').css("display","none");
		$('.carousellCenter[itemid="'+ itemid + '"]').css("display","block");
		
		
		/*
		
		$('.carousellOverayContentItem[itemid="'+ prevImage + '"]').fadeOut(500,function(){
																							
																								   $('.carousellOverayContentItem[itemid="'+ itemid + '"]').fadeIn(500);
 });*/


assignreportname(itemid) ;
 

 $('.carousellImagesListItem[itemid="'+ prevImage + '"]').animate({ 
			top: 10,opacity:0.5
		}, 1000 );
		
		
		
		
		$('.carousellImagesListItem[itemid="'+ itemid + '"]').animate({ 
			top: 0,opacity:1
		}, 1000 );	

			var version=getInternetExplorerVersion();
		
		if(version>=8)
		{

		$('.carousellImagesListItem[itemid="'+ prevImage + '"] img').animate({ 
			top: 0,filter:"alpha(opacity=50)"
		}, 1000 );

		$('.carousellImagesListItem[itemid="'+ itemid + '"] img').animate({ 
			top: 0,filter:"alpha(opacity=100)"
		}, 1000 );	


		
		}
		
		prevImage = currentImage;
		
		
	
		$(".carousellImagesScroller").animate({ 
			left: startX - ( (itemid-1) * imageLength)
		}, 1500 );	

	
		return false;
	}
	
	
	
	
	
	
	
	function getInternetExplorerVersion()
{   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}
	
	
	
	
	
	
	
	
	
	
	function showNextImage(){
		currentImage++;
		if(currentImage > imagesCount){
			currentImage = 1;
		}			
		showImage(currentImage);
		return false;
	}
	
	function showPrevImage(){
		currentImage--;
		if(currentImage < 1){
			currentImage = imagesCount;
		}			
		showImage(currentImage);
		return false;
	}
	
	$("#scroller").css("left","1000px");
	
	//add fade to all images
	
	//$('.carousellImagesListItem').css("opacity","0.5")
	
	
	
	var centerNumber = Math.ceil(imagesCount / 2);
	centerNumber=1;
	
 $('.carousellImagesListItem[itemid!="'+ centerNumber + '"]').css("top","10px");
	$('.carousellImagesListItem[itemid="'+ centerNumber + '"]').css("top","10px");
	//assignreportname(centerNumber);
	var version=getInternetExplorerVersion();
	if(version>=8)
		{
		$('.carousellImagesListItem[itemid!="'+ centerNumber + '"] img').css("filter","alpha(opacity=50)");
		$('.carousellImagesListItem[itemid="'+ centerNumber + '"] img').css("filter","alpha(opacity=100)");
		
		}
	
	$('.carousellImagesListItem[itemid!="'+ centerNumber + '"]').css("opacity","0.5");
	
	
	
	
	$('.carousellImagesListItem[itemid="'+ centerNumber + '"]').css("opacity","1");
	
	/*
	
	
	*/
	//showImage(1);
	
	currentImage = centerNumber;
	prevImage = centerNumber;
	showNextImage();
	// need to show the center object
	
	/* remove the timer
	$(".carousell").hover(disableCarousellTimer,enableCarousellTimer);
	

	function timerToNext(){
		currentImage++;
		if(currentImage > imagesCount){
			currentImage = 1;
		}			
		showImage(currentImage);
	}
	
	function disableCarousellTimer(){
		$(document).stopTime("carouselltimer");
	}
	
	function enableCarousellTimer(){
		$(document).everyTime(6000, "carouselltimer",timerToNext);
	}
	
	$(document).everyTime(6000, "carouselltimer",timerToNext);*/
}
function assignreportname(itemid)
{
itemid="itemid-"+itemid;
if(document.getElementById(itemid))
{


try
{
document.getElementById("print_reportname").innerHTML=document.getElementById(itemid).childNodes[0].childNodes[0].title;
 }
 catch(e)
 {
 document.getElementById("print_reportname").innerHTML=document.getElementById(itemid).childNodes[1].childNodes[1].title;
 }



}

}
function newsTicker(){
	
	//number the imagesCount
	var counter = 1;
	var newsItems = 0;
	$(".newstickerNewsItem").each(function(){
		var target = $(this);
		target.attr("itemid", counter);
		
		counter++;
		newsItems++;
	});
	
	var currentItem = 1;
	
	function timerAnim(){
		$('.newstickerNewsItem[itemid="'+ currentItem + '"]').animate({top: -39}, 500,resetTop);
		currentItem++;
		
		if(currentItem > newsItems){
			currentItem = 1;
		}
		
		
		$('.newstickerNewsItem[itemid="'+ currentItem + '"]').animate({top: 0}, 500);
		function resetTop(){
			var target = currentItem-1;
			$(this).css("top","39px");
		}
	}
	
	//timerAnim();
	
	$(document).everyTime(4500, "nestickertimer", timerAnim);

}

function naviPopup(){
	var target = $("#naviPopup");
	
	
	var highest = 0;
	
	target.css("display", "block");
	target.css("visibility", "hidden");
	
	target.find(".naviContent").each(function(){
			$(this).css("display", "block");
			if($(this).height() > highest){
				highest = $(this).height();
			}
	});
	
	target.find(".naviContents").css("height", highest+"px");
	
	
	//number the links and containers
	var counter = 1;
	
	target.find(".naviContent").each(function(){
		var target = $(this);
		target.attr("itemid", counter);
		// set the first to visible
		if(counter == 1){
			target.css("display","block");
		}else{
			target.css("display","none");
		}
	
		counter++;
	});
	
	
	
	var counter = 1;
	target.find(".naviItems a").each(function(){
		var target = $(this);
		target.attr("itemid", counter);
		
		//set the fist to active
		
		if(counter == 1){

			target.addClass("active");
		}
		
		
		// add function to show the right container when clicked	
		
		target.click(showContainer);
		
		counter++;
	});
	
	
	
	
	target.css("visibility", "visible");
	target.css("display","none");
	
	
	
	target.find('.naviContent[itemid="1"]').css("display","block");
	
	
	// set the first as the previous item
	var prevItem = target.find('.naviItems a[itemid="1"]');
	
	function showContainer(){
		var callerLink = $(this);
		
		// return if clicked the active
		
		if(callerLink.attr("itemid") == prevItem.attr("itemid")){
			return;
		}
		
		callerLink.addClass("active");
		prevItem.removeClass("active");
		
		target.find('.naviContent').css("display","none");
		target.find('.naviContent[itemid="'+callerLink.attr("itemid")+'"]').css("display","block");
		
		/*target.find('.naviContent[itemid="'+prevItem.attr("itemid")+'"]').slideUp(500,hide);
		target.find('.naviContent[itemid="'+callerLink.attr("itemid")+'"]').slideDown(1000);
		function hide(){
			
		}*/
		
		prevItem = callerLink;
		return false;
	}
	
	
	
}