/* jquery mouse wheel */
/* /js/jquery.mousewheel-3.0.2.pack.js */
(function(b){function d(a){var f=[].slice.call(arguments,1),e=0;a=b.event.fix(a||window.event);a.type="mousewheel";if(a.wheelDelta)e=a.wheelDelta/120;if(a.detail)e=-a.detail/3;f.unshift(a,e);return b.event.handle.apply(this,f)}var c=["DOMMouseScroll","mousewheel"];b.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=c.length;a;)this.addEventListener(c[--a],d,false);else this.onmousewheel=d},teardown:function(){if(this.removeEventListener)for(var a=c.length;a;)this.removeEventListener(c[--a],
d,false);else this.onmousewheel=null}};b.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);

// social networking box
$(document).ready(function() {
 // hides the #socialbox as soon as the DOM is ready
 // (a little sooner than page load)
  //$('#socialbox').hide();

 // toggles the #socialbox on clicking the noted link
 // $('a#toggleSocial').click(function() {
   // $('#socialbox').toggle(400);
   // return false;
  //});



	// toggles the #am-status-open-container on clicking the noted link
	$('a#toggleSocial').click(function() {
		$('#socialbox').animate({ height: 'toggle' }, 400);
		return false;
	});
});
// left sub menu animation
function ShowHide(menuItem, linkObj){
	$("#"+menuItem).animate({height: "toggle", duration: 500}, changeImg(linkObj));
}
function changeImg(theObj){
	if(theObj.childNodes[0].src.indexOf('menu-plus') >= 0)
		theObj.childNodes[0].src = '/images/menu-minus.gif';
	else
		theObj.childNodes[0].src = '/images/menu-plus.gif';
}

// show the extra options in the forms
function ShowHide2(theState, theDiv){
	if(theState*1 == 1)
		$("#"+theDiv).show("slow");
	if(theState*1 == 0)
		$("#"+theDiv).hide("fast");
}

// show the details in qualifications center
function ShowHideQuals(linkObj, theDiv){

	$("#"+theDiv).animate({height: "toggle", duration: 500});

	if(linkObj.className == 'closed')
		linkObj.className = 'open';
	else
		linkObj.className = 'closed';
}


// cookie functions
// create cookie
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=/";
}

// read cookie
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;
}

// delete cookie
function eraseCookie(name) {
	createCookie(name,"",-1);
}


// style switcher
function textSize(theSize){
	//reset
	document.getElementById('styleSwitch01').src = '/images/fr/toolbox-01.gif';
	document.getElementById('styleSwitch02').src = '/images/fr/toolbox-02.gif';
	document.getElementById('styleSwitch03').src = '/images/fr/toolbox-03.gif';

	switch(theSize*1){
		case 1:
			document.getElementById('styleswitcher').href = '/css/font-size-1.css';
			document.getElementById('styleSwitch01').src = '/images/fr/toolbox-01-on.gif';
			createCookie('styleSwitch',1,7);
			break;
		case 2:
			document.getElementById('styleswitcher').href = '/css/font-size-2.css';
			document.getElementById('styleSwitch02').src = '/images/fr/toolbox-02-on.gif';
			createCookie('styleSwitch',2,7);
			break;
		case 3:
			document.getElementById('styleswitcher').href = '/css/font-size-3.css';
			document.getElementById('styleSwitch03').src = '/images/fr/toolbox-03-on.gif';
			createCookie('styleSwitch',3,7);
			break;
		default:
			document.getElementById('styleswitcher').href = '/css/font-size-1.css';
			document.getElementById('styleSwitch01').src = '/images/fr/toolbox-01-on.gif';
			createCookie('styleSwitch',1,7);
			break;
	}
}
$(document).ready(function() {
	if(document.getElementById('styleSwitch01'))
	textSize(readCookie('styleSwitch'));
});

// style switcher
function textSizeFoundation(theSize){
	//reset
	document.getElementById('styleSwitchFoundation01').src = '/images/foundation/toolbox-01.gif';
	document.getElementById('styleSwitchFoundation02').src = '/images/foundation/toolbox-02.gif';
	document.getElementById('styleSwitchFoundation03').src = '/images/foundation/toolbox-03.gif';

	switch(theSize*1){
		case 1:
			document.getElementById('styleswitcher').href = '/css/font-size-1.css';
			document.getElementById('styleSwitchFoundation01').src = '/images/foundation/toolbox-01-on.gif';
			createCookie('styleSwitchFoundation',1,7);
			break;
		case 2:
			document.getElementById('styleswitcher').href = '/css/font-size-2.css';
			document.getElementById('styleSwitchFoundation02').src = '/images/foundation/toolbox-02-on.gif';
			createCookie('styleSwitchFoundation',2,7);
			break;
		case 3:
			document.getElementById('styleswitcher').href = '/css/font-size-3.css';
			document.getElementById('styleSwitchFoundation03').src = '/images/foundation/toolbox-03-on.gif';
			createCookie('styleSwitchFoundation',3,7);
			break;
		default:
			document.getElementById('styleswitcher').href = '/css/font-size-1.css';
			document.getElementById('styleSwitchFoundation01').src = '/images/foundation/toolbox-01-on.gif';
			createCookie('styleSwitchFoundation',1,7);
			break;
	}
}
$(document).ready(function() {
	if(document.getElementById('styleSwitchFoundation01'))
	textSizeFoundation(readCookie('styleSwitchFoundation'));
});



// set the boxes to all the same height on the home page
$(document).ready(function() {
	if(document.getElementById('box01')){
		var current01 = document.getElementById('box01').offsetHeight;
		var current02 = document.getElementById('box02').offsetHeight;
		var current03 = document.getElementById('box03').offsetHeight;
		var newHeight;

		if(current01*1 >= current02*1 && current01*1 >= current03*1) newHeight = current01*1 + 'px';;
		if(current02*1 >= current01*1 && current02*1 >= current03*1) newHeight = current02*1 + 'px';;
		if(current03*1 >= current01*1 && current03*1 >= current02*1) newHeight = current03*1 + 'px';;

		document.getElementById('box01').style.height = newHeight;
		document.getElementById('box02').style.height = newHeight;
		document.getElementById('box03').style.height = newHeight;
	}
});

// Limit text length to supplied value
function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}

// Open a new target for links beginning with http/https
$(document).ready(function() {
    $("a[href^='http://']").click(function(){
    	//pageTracker._link = this.href;
    	_gaq.push(['_link', this.href]); 
        if(this.rel != 'internal'){
            this.target = "_blank";    
        }
    }); 
    
    $("a[href^='https://']").click(function(){
    	//pageTracker._link = this.href;
    	_gaq.push(['_link', this.href]); 
        if(this.rel != 'internal'){
            this.target = "_blank";    
        }
    });
});

// Remove default value form a text box
function emptyDefault(field, defaultValue) {    
    if(field.value == defaultValue) {
        field.value = "";
        return true;
    }        
}

// Initialize a textbox with default value    
function fillWithDefault(field, defaultValue) {    
    if(field.value == '') {
        field.value = defaultValue;
        return true;
    }
}

function switchToNext(el) {
    if (el.value.length < el.getAttribute('maxlength')) return;

    var nextEl = el.form.elements[el.tabIndex+2];        
    if (nextEl && nextEl.focus) nextEl.focus();
}


// tabs for the results page
function showHideResults(linkObj, theDiv, theYear){
	
	// reset all the tabs
	var cellArray = document.getElementById('results-pagination').getElementsByTagName('td');
	var i=0;
	for (i=0; i<cellArray.length; i++){
		cellArray[i].className = 'off';
	}
	linkObj.parentNode.className = 'on'; 

	// reset all the divs
	var cellArray = document.getElementById('body-content').getElementsByTagName('div');
	var j=0;
	for (j=0; j<cellArray.length; j++){
		if(cellArray[j].className == 'results-divs')
			cellArray[j].style.display = 'none';
	}
	document.getElementById(theDiv).style.display = 'block';

	// change the year
	document.getElementById('resultsYear').innerHTML = theYear;
}
