// Script to randomly display any number of images
// Edit "var movie = " to one less than the number of movies you will have
// Add an array index for each movie: movie[2]="/path/to/thirdmovie.swf"
//changed 4000 to 4050 swf per Betrand
// SolutionSet, Tri Doan
function writeImage() {
		var howMany = 4;
		var movie = new Array(howMany+1);
		movie[4]="/images/side_ann.png";
		movie[3]="/images/side_vince_jane.png";
		movie[2]="/images/side_graham.png";
		movie[1]="/images/side_family.png";
		movie[0]="/images/side_couple.png";
		function rndnumber() {
			var randscript = -1;
			while (randscript < 0 || randscript > howMany || isNaN(randscript)) {
				randscript = parseInt(Math.random()*(howMany+1));
			}
			return randscript;
		}
		quo = rndnumber();
		quox = movie[quo];
		
		if(document.getElementById('rotatingImage')) {
			document.getElementById('rotatingImage').src = quox;
		
		}
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<div " + imgID + imgClass + imgTitle // change span to div to check if this resolves the issue.
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></div>"
	   myImage.outerHTML = strNewHTML	  
    }
}

//enable popup if cookie doesn't exist

window.onload=function() {
	writeImage();
	openPopup('info_popup.html',500,285);
}

function openPopup(url,pop_width,pop_height) {
	
	var good = getCookie('gomindego');
	
	if (!good) {
		var h,w 
		h = screen.height; //height of screen, not just the parent window 
		w = screen.width; //width of the screen, not just the parent window 
		var l,t 
		l = parseInt((w/2)-(pop_width/2)); 
		t = parseInt((h/2)-(pop_height/2)-60); 
		//t = parseInt((pop_height)/2-20); 
		//alert(h+" "+w+" "+l+" "+t);
		popupWin = window.open(url,'open_window','scrollbars=no,resizable=no,width='+pop_width+',height='+pop_height+',left='+l+',top='+t);
		setCookie('gomindego', true);
	} 
}

/******* cookies *********/


function setCookie(name, value, expires) {
	// no expiration date specified? use this date and it will just be deleted soon.
        if (!expires) expires = new Date("December 31, 2050"); 
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";

}
	//var expdate = new Date (); // pre-set to the current time and date
	//expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24 * 365); // add one year to it 
	//365 days/year * 24 hours/day * 60 minutes/hour * 60 seconds/minute * 1000 milliseconds/second
	// = howevermany milliseconds/year. So this adds one year, it'll expire in one year.


function getCookie(name) {
	var cookies = document.cookie;
	if (cookies.indexOf(name) != -1)
	{
		var startpos = cookies.indexOf(name)+name.length+1;
		var endpos = cookies.indexOf(";",startpos)-1;
		if (endpos == -2) endpos = cookies.length;
		return unescape(cookies.substring(startpos,endpos));
	}

	else
	{
		return false; // the cookie couldn't be found! it was never set before, or it expired.
	}
}
