//Header Image Mouseover Handeling
var ImageWatcher = Class.create();
ImageWatcher.prototype = {
	initialize: function(img, message) {
		this.img = $(img);
		this.message = message;
		this.img.onmouseover = this.doMouseOver.bindAsEventListener(this);
		this.img.onmouseout = this.doMouseOut.bindAsEventListener(this);
	},
	doMouseOver: function(evt) {
		this.img.bksrc = this.img.src;
		this.img.src = this.message;
	},
	doMouseOut: function(evt) {
		this.img.src = this.img.bksrc;
	}
};

function LoadMainHeader() {
	var dir = '/QP4Assets/13447/custom/images/en/header/buttons/';
	if( $('btnHome_SP') != null) {
		dir = '/QP4Assets/13447/custom/images/sp/header/buttons/';
	}
	
	if( $('btnHome') != null)
		new ImageWatcher('btnHome', dir + 'home2.jpg');
	if($('btnCustomerService') != null)
		new ImageWatcher('btnCustomerService', dir + 'cs2.jpg');
	if($('btnQuestions') != null)
		new ImageWatcher('btnQuestions', dir + 'quest2.jpg');
	if($('btnEventDirectors') != null)
		new ImageWatcher('btnEventDirectors', dir + 'directors2.jpg');
	if($('btnSpanish') != null)
		new ImageWatcher('btnSpanish', '/QP4Assets/13447/custom/images/en/header/buttons/lang2.jpg');
		
	if($('btnSchedule') != null)		
		new ImageWatcher('btnSchedule', dir + 'Sched2.jpg');
	if($('btnOrganizer') != null)		
		new ImageWatcher('btnOrganizer', dir + 'Org2.jpg');		
		
	if( $('btnHome_SP') != null)
		new ImageWatcher('btnHome_SP', dir + 'home2.jpg');
	if($('btnCustomerService_SP') != null)
		new ImageWatcher('btnCustomerService_SP', dir + 'cs2.jpg');
	if($('btnQuestions_SP') != null)
		new ImageWatcher('btnQuestions_SP', dir + 'quest2.jpg');
	if($('btnEventDirectors_SP') != null)
		new ImageWatcher('btnEventDirectors_SP', dir + 'directors2.jpg');
	if($('btnEnglish') != null)
		new ImageWatcher('btnEnglish', '/QP4Assets/13447/custom/images/sp/header/buttons/lang2.jpg');
}

function LoadEventHeader() {
	var dir = '/QP4Assets/13447/custom/images/en/header/buttons/';
	if( $('btnHome_SP') != null) {
		dir = '/QP4Assets/13447/custom/images/sp/header/buttons/';
	}
		
	if( $('btnHome') != null)
		new ImageWatcher('btnHome', dir + 'home2.jpg');
	if($('btnCustomerService') != null)
		new ImageWatcher('btnCustomerService', dir + 'cs2.jpg');
	if($('btnQuestions') != null)
		new ImageWatcher('btnQuestions', dir + 'quest2.jpg');
	if($('btnResults') != null)
		new ImageWatcher('btnResults', dir + 'Results2.jpg');
	if($('btnLost') != null)
		new ImageWatcher('btnLost', dir + 'Lost2.jpg');	
	if($('btnEmail') != null)
		new ImageWatcher('btnEmail', dir + 'email2.jpg');	
	if($('btnCertificate') != null)
		new ImageWatcher('btnCertificate', dir + 'cert2.jpg');					
		
		
	if( $('btnHome_SP') != null)
		new ImageWatcher('btnHome_SP', dir + 'home2.jpg');
	if($('btnCustomerService_SP') != null)
		new ImageWatcher('btnCustomerService_SP', dir + 'cs2.jpg');
	if($('btnQuestions_SP') != null)
		new ImageWatcher('btnQuestions_SP', dir + 'quest2.jpg');
	if($('btnResults_SP') != null)
		new ImageWatcher('btnResults_SP', dir + 'Results2.jpg');
	if($('btnLost_SP') != null)
		new ImageWatcher('btnLost_SP', dir + 'Lost2.jpg');	
	if($('btnEmail_SP') != null)
		new ImageWatcher('btnEmail_SP', dir + 'email2.jpg');	
	if($('btnCertificate_SP') != null)
		new ImageWatcher('btnCertificate_SP', dir + 'cert2.jpg');			
		
}

// Lost & Found Handeling
function LAF(code) {
	window.location = "http://www.sportphoto.com/Redirect.aspx?Location=LostAndFoundRedirect&Code=" + code;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function HideLAF() {
	if(document.getElementById('divLAF') != null && document.getElementById('divLAF').style != null) {
		document.getElementById('divLAF').style.display='none';
	
		var f1 = document.getElementById('flashobj1');
		if(f1 != null) {
			f1.style.visibility = "visible";
		}		
	}
}
function ShowLAF() {
	var x = document.getElementById('divLAF');

	if(x != null && (document.getElementById('txtEmail') != null || document.getElementById('labEventExpiredOn') != null)) {
		x.innerHTML = "The event is not currently available.";
	}

	var btn = document.getElementById('btnLost');
	if(btn == null) {
		btn = document.getElementById('btnLost_SP');
	}
	
	var f1 = document.getElementById('flashobj1');
	if(f1 != null && f1.style != null) {
		f1.style.visibility = "hidden";
	}

			
	var coors = findPos(btn);
	if(x != null && x.style != null) {
   	   x.style.top = (coors[1] + 90) + 'px';
	   x.style.left = (coors[0] - 200) + 'px';	
	   x.style.display='';
	}

}


function LAF_Load() {
	var myAjax = new Ajax.Request('XML/LostAndFound.aspx', {method: 'get', parameters: 'Random=' + Math.random(10000), onComplete: LAF_callback});
}

function LAF_callback(response) {
	var xmlobj = Try.these(
		function() { return new DOMParser().parseFromString(response.responseText, 'text/xml'); },
		function() { var xmldom = new ActiveXObject('Microsoft.XMLDOM'); xmldom.loadXML(response.responseText); return xmldom; }
	);		
	
	var x = document.getElementById('divLAF');
	var s = "";
	var Codes = xmlobj.getElementsByTagName("SpotCode");
	if(Codes.length > 0) {
		s += "<center><b>Choose a Lost &amp; Found Category</b></center><br>";
		for(var i = 0; i < Codes.length; i++) {
			s += "<a href=\"javascript:LAF('" + Codes[i].getAttribute("Code") + "');\">" + Codes[i].getAttribute("Description") + "</a><br>";
		}
		x.innerHTML = s;
	}
	
}
