
function PopUp(URL) {
	
	//day = new Date();
	//id = day.getTime();
	
	//eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=950,height=670,left = 100,top = 100');");
	window.location.href=URL;
}


function StarckPopUp(URL) {
	
	day = new Date();
	id = day.getTime();
	
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=590,height=395,left = 100,top = 100');");

}

$(document).ready(function(){

	// code to handle image transitions (along with ad refreshes & omniture stats updating)
	
	// if IE 6, give up now...
	isIE6=(navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1);
	if (isIE6) {
		return;
	}
	
	// split testing code
	if(typeof readCookie == 'function') {
		if (readCookie('jsGallery') == 'false') {
			return;
		}
	}
	
	// how many images do we have? Get this here for use in various loops below
	var arrayLength = imagesArray.length;
	
	// bookmarked image - will be numeric ID in location hash
	if ((parent.location.hash != '') && (parent.location.hash.substring(1) == parseInt(parent.location.hash.substring(1)))) {
		currentImageID=parseInt(parent.location.hash.substring(1));
		for (var i=0;i<arrayLength;i++) {
			if (parseInt(imagesArray[i]['image_group_id']) === currentImageID) {
				currentImage = i;
				break;
			}
		}
		if ((currentImage) && (imagesArray[currentImage])) {
			var myElem = $('div#topSectionGallery').children('a').children('img:first-child');
			if (myElem) {
				myElem.attr('src',imagesArray[currentImage]['filename']);
			
				// now change the displayed image counter
				var myListElem = $('ul#prevNextLinks').children('li:first-child');
				if (myListElem) {
					myListElem.html((currentImage+1) + ' of ' + arrayLength);
				}
				
				// now swap out the caption
				var myCaptionElem = $('p#imageCaption');
				if (myCaptionElem) {
					myCaptionElem.text(unescape(imagesArray[currentImage]['image_caption'])).html();
				}
			}
		}
	}
	
	var block = false; // timeout, prevent clicking through too rapidly
	
	// add event handlers to the back and forward links
	$('a.prev, a.next').click(function(event){

		if (block) {
			return false;
		}
		
		// load ads first
		
		// array of divs [IDs] containing ads
		var adDivs = new Array ('topBanner','mpu','sky');  
		
		var adDivsLength=adDivs.length;
		
		// now update the ad divs/iframes
		for (var i=0;i<adDivsLength;i++) {
			var myDiv = adDivs[i];
			
			if ($('#'+myDiv).is('div')) { // first call after page load, so convert div to iframe
				var myIFrame;
				if (document.createElement && (myIFrame = document.createElement('iframe'))) {
					// set correct display/css properties
					// clone some of the div css properties
					$(myIFrame).css({border : '0', overflow : 'hidden', width : $('div#'+myDiv).css('width'), height : $('div#'+myDiv).css('height'), margin : $('div#'+myDiv).css('margin') } );
					
					// set HTML attributes
					$(myIFrame).attr({frameborder : '0', scrolling : 'no', id : myDiv });
					
					$('div#'+myDiv).replaceWith($(myIFrame));
					myIFrame.src='/content/adtech/'+myDiv+'.html';
				}
			} else if ($('#'+myDiv).is('iframe')) { // subsequent call after page load, so already converted to iframe
				document.getElementById(myDiv).contentWindow.location.reload(true);
			}
		
		}
		
		// now post meta data to omniture
		if (typeof s != "undefined") {
			void(s.t());
		}
		
		// now load new image
		
		// in which direction are we going?
		if ($(this).hasClass('next')) {
			currentImage++;
			if (currentImage == arrayLength) { // loop back to start
				currentImage = 0;
			}
		} else if ($(this).hasClass('prev')) {
			currentImage--;
			if (currentImage < 0) { // loop back to end
				currentImage = (arrayLength - 1);
			}
		}
		
		var myElem = $('div#topSectionGallery').children('a').children('img:first-child');
		if (myElem) {
			myElem.attr('src',imagesArray[currentImage]['filename']);
			
			// now change the displayed image counter
			var myListElem = $('ul#prevNextLinks').children('li:first-child');
			if (myListElem) {
				myListElem.html((currentImage+1) + ' of ' + arrayLength);
			}
			
			// now swap out the caption
			var myCaptionElem = $('p#imageCaption');
			if (myCaptionElem) {
				myCaptionElem.text(unescape(imagesArray[currentImage]['image_caption'])).html();
			}
		} else {
			return;
		}
		
		// add to hash for bookmarking purposes
		parent.location.hash = imagesArray[currentImage]['image_group_id'];

		delay = 0; // time in milliseconds of delay between clicks
		
		if (delay > 0) {
			block = true; // put a block on rapid click-throughs
			window.setTimeout(function() {
				block = false;
			}, delay);
		}
		
		return false;  // prevent the href action of the links
	});

	// calculate the currently displayed image
	var currentImageFileName=$('div#topSectionGallery').children('a').children('img').attr('src');
	if (currentImageFileName) {
		for (var i=0;i<arrayLength;i++) {
			if (imagesArray[i]['filename'] == currentImageFileName) {
				currentImage = i;
				break;
			}
		}
	}
	
	// do some image preloading to speed things up
	for (var i=0;i<arrayLength;i++) {
		eval ("img" + i + "= new Image();");
		eval ("img" + i + ".src = imagesArray[i]['filename'];");
	}
	
	
});