// ---------------------------------------------------	*

// UTILITY.JS											*

// Pop-ups, promotion-specific functions	*

// ---------------------------------------------------	*







$(function() {

		prepareLinks();

      });









// ~~~~~pop-ups~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function prepareLinks() {

	

	if(document.getElementsByTagName) {

		var link = document.getElementsByTagName('a');

		var area = document.getElementsByTagName('area');

	} else { 

		var link = document.links;

	}

	

	for(j=0; j<area.length; j++) {

		//uses the class attribute for image map because "rel" is an invalid attribute for area tags

		var linkClass = area[j].className;



		if(linkClass == 'subWindow') { //sub window

			area[j].onclick = function() {

				return newWindow(this.getAttribute('href'));

			}

		}		

	}

	

	for(i=0; i<link.length; i++) {

		//uses the "rel" attribute of the link to determine link behavior

		var linkBehavior = link[i].getAttribute('rel');

		

		if(linkBehavior == 'prize') { //pop-up

			link[i].onclick = function() {

				return openPrize(this.getAttribute('href'));

			}

		}	



		if(linkBehavior == 'prizecntr') { //pop-up centered

			link[i].onclick = function() {

				return openPrizeCntr(this.getAttribute('href'));

			}

		}	



		if(linkBehavior == 'new') { //sub window

			link[i].onclick = function() {

				return newWindow(this.getAttribute('href'));

			}

		}



		if(linkBehavior == 'external') { //new full browser window

			link[i].onclick = function() {

				return externalWindow(this.getAttribute('href'));

			}

		}



		if(linkBehavior == 'close') {//for close buttons

			link[i].onclick = function() {

				return closeWindow();

			}

		}

		

		if(linkBehavior == 'tb_close') {//for thickbox close buttons

			if(window.opener){//checks to see if this is a sub-window

				link[i].onclick = function() {

					return closeWindow();

				}

			}

			else {//implements close functionality for a thickbox pop-up

				link[i].onclick = function() {

					return closeTBWindow();

					

				}

			}

			

		}

		

		if(linkBehavior == 'back') {//for back buttons

			link[i].onclick = function() {

				return goBack();

			}

		}

		

		if(linkBehavior == 'print') {//for back buttons

			link[i].onclick = function() {

				return printPage();

			}

		}

		

	}	

}





//____________ JS buttons ____________

function closeWindow() {

	self.close();

	return false;

}



function closeTBWindow() {

	//var t=setTimeout("alert('focused');",3000);

	self.parent.tb_remove();

	return false;

}



function goBack() {

	history.go(-1);

	return false;

}



function printPage() {

	window.print();

	return false;

}





// ____________ pop-up variations _________________

// ____________ flash pop up _________________

function flashPopUp(url) { //called inline in flash movie

	newwindow=window.open("page.do?page="+url,"prize","width=765,height=685,scrollTo,resizable=0,scrollbars=1");

	if (window.focus) {newwindow.focus()}

}





// ----- html functions -----

function openPrize(url) {

	newwindow=window.open(url,"prize","width=420,height=400,scrollTo,resizable=0,scrollbars=1");

	if (window.focus) {newwindow.focus()}

	return false;	

}



function newWindow(url) {

	newwindow=window.open(url,"window","width=800,height=600,scrollTo,resizable,status,directories,menubar,location,toolbar,scrollbars,resizable");

	if (window.focus) {newwindow.focus()}

	return false;

}





function externalWindow(url) {

	newwindow=window.open(url,"external");

	if (window.focus) {newwindow.focus()}

	return false;

}



function openPrizeCntr(url) {

	

	popWidth= 420;

	popHeight= 400;

	var t = (screen.height-popHeight)/2;

	var l = (screen.width-popWidth)/2;

	newwindow=window.open(url,"prizecntr","width="+popWidth+",height="+popHeight+",top="+t+",left="+l+"scrollTo,resizable=0,scrollbars=1");

	if (window.focus) {newwindow.focus()}

	return false;	

}







// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

