

// WAIT FOR PAGE TO LOAD AND THEN INITIALIZE
$(document).ready(function() {

	jQuery(function($) {
		$("img").pngfix();
	});
	
	// language switcher onchange handler
	$('li.lang select').change(function() {
		$('input#languageChange').attr('value','1');
		this.form.submit();
	});
	
	// LISTEN FOR IMAGE GALLERY PREVIEW BEING ROLLED OVER
	$('.imagePreviewMask').bind("mouseenter",function() {
		$(this).addClass('imagePreviewMaskOver');
	});
		// LISTEN FOR IMAGE GALLERY PREVIEW BEING ROLLED OVER
	$('.imagePreviewMask').bind("mouseleave",function() {
		$(this).removeClass('imagePreviewMaskOver');
	});
	
	// LISTEN FOR SEASON HUB RESULTS TABS BEING CLICKED
	$('.resultsTabs li a').click(function() {
	
		var resultsTabListItems = $('.resultsTabs li');
		var resultsTabContent = $('.resultsWrapper');
	
		// loop over all the tabs and matching content blocks removing the relevant class
		for (var i=0; i<resultsTabListItems.length; i++) {
			$(resultsTabListItems[i]).removeClass('selectedResultsTab');
			$(resultsTabContent[i]).removeClass('resultsWrapperShow');
		}
		// determine the tab ID and and add the relevant class to the tab and its content
		var tabId = $(this).attr("id").split("Link")[0];
		
		$("#" + tabId + "Wrapper").addClass('resultsWrapperShow');
		$(this).parent().addClass('selectedResultsTab');
		return false;
	});
	
	
    // LISTEN FOR SOCIAL BOOKMARK LINKS ROLLOVERS
    $('a.social').hover(
        function() {
            $('#bookmarkName').html($(this).html());
        },
        function() {
            $('#bookmarkName').empty();
        }
    );

	
	
});




// find mouse coordinates
function findMousePos(event) {
	// make sure we get hold of the event in both firefox and IE style event handling
	if( !event ){ var event = window.event; }
	var xMouse = event.clientX;
	var yMouse = event.clientY;
	return [xMouse,yMouse];
}

// find an element position
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

//convert links with rel external to target _blank to maintain strict compat
function targetBlank() {
	if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external"){
			anchor.target = "_blank";
		}
	}
}

// function to allow javascript to programmatically load a CSS stylesheet
function loadStylesheet( filename, media ){
	// ensure that the browser has all the DOM methods/properties we need
	if( !(document.getElementById) ||
		!(document.childNodes) ||
		!(document.createElement) ||
		!(document.getElementsByTagName) ){
		return;
	}

	// make a new link node to the stylesheet
	var link = document.createElement( "link" );
	link.href = filename;
	link.rel = "stylesheet";
	link.type = "text/css";
	link.media = media;

	// insert the stylesheet link into the document head
	document.getElementsByTagName('head')[0].appendChild(link);
}

// load listener to load multiple fns onload
function addLoadEvent( func ){
	// if there isn't currently an onload function...
	if( typeof window.onload != "function" ){
		// ...then just set it to this one
		window.onload = func;
	} else {
		// otherwise, remember the old onload function
		var oldOnloadFn = window.onload;
		// and make a new onload function that will call the old one, and then func
		window.onload = function() {
			if( oldOnloadFn ) {
				oldOnloadFn();
			}
			func();
		};
	}
}

