document.write('<style>');
document.write('	#header ul.navigation li:hover ul { display:none; }');
document.write('</style>');

$(document).ready(function(){
									
	// attach ga tracking to no webpage links
	// GALinker.attach();					

	// validation for any forms
  $("#form-login").validate();  				
  $("#form-advanced-search").validate();  		
	
	$('#header ul.navigation > li').mouseenter(function(){
																		 
		var position = $(this).position();
		var top = position.top;
		var left = position.left;
		var width = $(this).width();
		var height = $(this).height();
		
		// Firefox 2 bug fix
		if ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)) {
			top -= 1;
		}		

		if ($(this).find('a').hasClass('hover')) {
			return false;
		}

		// IE6 bug fix - hide all selects to avoid layer overlay problem
		if ($.browser.msie  && (parseFloat($.browser.version) <= 6)) {
			$('select').hide();
		}
		
		$(this).find('ul').css('top',top+height);
		$(this).find('ul').css('left',left);
		$(this).find('ul').css('width',width);

		var self = $(this);
		self.find('a').addClass('delay');
		
		setTimeout(function() {
								  
			if (!self.find('a').hasClass('delay')) {
				self.find('a').removeClass('delay');				
				return false;
			}						
						
			self.find('a').addClass('hover');
			self.find('ul').slideDown('fast');
			self.find('a').removeClass('delay');
								  
		}, 500);

		
	}).mouseleave(function() {
		var self = $(this);

		// IE6 bug fix - hide all selects to avoid layer overlay problem
		if ($.browser.msie  && (parseFloat($.browser.version) <= 6)) {
			$('select').show();
		}

		if ($(this).find('a').hasClass('delay')) {
			self.find('a').removeClass('delay');				
			return false;
		}

		$(this).find('ul').slideUp('fast', function() {
			self.find('a').removeClass('hover');
		});
	});
	
	                $('#zztrigger-login').click(function(event) {

                                event.preventDefault();

				var link = $(this).attr('href');
				var qsPos = link.indexOf('?');
				var qs = link.substring(qsPos, link.length);
var url = "/cps/rde/xchg/cpa-site/hs.xsl/form-login2.html";
if (qsPos >= 0)
 {
url += qs;
}
$(this).find('span').replaceWith('&#9650;');

                               

                                $.get(url, function(data){

                                                var htmlData = $(data).find("#form-login").html();

                                                var action = $(data).find("#form-login").attr('action');

      htmlData = '<form method="post" id="overlay-form-login" action="' + action + '">' + htmlData + '</form>';

                                                Overlay.width = 250;

                                                Overlay.opacity = 80;

                                                Overlay.setStyle('overlay');

                                                Overlay.show(htmlData, function() {
         $("#overlay-form-login input#txLogin").focus();
         $("#overlay-form-login").validate();

      });

      

                                });

                });

	
});

function decrease() {
	oHTML = document.getElementsByTagName('BODY')[0];
	oHTML.style.fontSize = parseInt(oHTML.style.fontSize)-10+"%";
//	window.status += oHTML.style.fontSize;

	// Update the cookie that holds the font size setting. Do this by calling the cookieMonster function, which
	// looks at the oHTML.style.fontSize; and updates the cookie value accordingly.  If a cookie doesn't exist it creates one.
	updateCookie();
}

function increase() {
	oHTML = document.getElementsByTagName('BODY')[0];
	oHTML.style.fontSize = parseInt(oHTML.style.fontSize)+10+"%";
//	window.status += oHTML.style.fontSize;

	// Update the cookie that holds the font size setting. Do this by calling the cookieMonster function, which
	// looks at the oHTML.style.fontSize; and updates the cookie value accordingly.  If a cookie doesn't exist it creates one.
	updateCookie();
}

function cookieMonster() {
	// This function looks at the oHTML.style.fontSize; and updates the cookie value accordingly.  If a cookie doesn't exist it creates one.
	var oHTML = document.getElementsByTagName('BODY')[0];

	// Look for the cookie that holds font size.  If found, set document to that font size, else set cookie to current font size.
	if(readCookie('fontSize')==null) {
		// No cookie found. Create a new cookie that is set to the font size as defined in the HTML tag on the page (70%).
		createCookie('fontSize',parseInt(oHTML.style.fontSize),365);	
	} else {
		// Cookie found.  Set the HTML font size to the value of the cookie.
		oHTML.style.fontSize = readCookie('fontSize')+"%";
//		window.status += readCookie('fontSize');
	}

	//alert('cookieMonster: ' + readCookie('fontSize'));
}

function updateCookie() {
	var oHTML = document.getElementsByTagName('BODY')[0];

	// Check if the cookie exists.  If not, create one.
	if(readCookie('fontSize')==null) {
		// Create a new cookie that is set to the font size as defined in the HTML tag on the page (70%).
		cookieMonster();	
	} else {
		// Cookie exists, so update it's value.  Look at the recently set font size as defined in the HTML tag on the page, which will have been increased/decreased.
		createCookie('fontSize',parseInt(oHTML.style.fontSize),365);
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0){
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// JavaScript Document
// jQuery main
$(function() {
			  
	$('#nav a').click(function() {
										
		$('#player li.active').stop();										
										
		$('#nav li.active').removeClass('active');
		$(this).parent('li').addClass('active');
										
		var load_clip = $(this).attr('href');
		
		$('#player li.active').fadeOut('fast', function() {
			$(this).removeClass('active');
			$(load_clip).fadeIn('slow');
			$(load_clip).addClass('active');
		});
										
	});
	
	// toolbar print button handler
	$('.launch-print').click(function(e) {
		e.preventDefault();						
		window.print();							
	});
	
	// toolbar decrease text size
	$('.text-decrease').click(function(e) {
		e.preventDefault();
		decrease();
	});
	
	// toolbar increase text size
	$('.text-increase').click(function(e) {
		e.preventDefault();
		increase();
	});	

	$('dl.search-results dd.keywords ul li:first-child').css('backgroundImage','none');

});

