﻿var popUpWin;
var swfId = "myFlash";
var weekLink = "";
var mySettings = "";
var popUpFail = false;

function reload() {
    document.location.reload(true);
    return true;
}

function openMyWindow(myUrl,myTarget) {
//	alert(myUrl + " " + myTarget);
	var tmp = myUrl.split("'");
	var newURL;
	
	if(tmp.length > 1) {
		newURL = tmp[1];
	} else {
		newURL = myUrl;
	}

	var winNew = window.open(newURL,myTarget);

	if(!winNew) {
		getSwf(swfId).openWindowFromSwf(myUrl);
	} else {
		winNew.focus();
	}
}

function getSwf(id) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[id];
	} else {
		return document.getElementById(id);
	}
}    


function openWinMessages(week) {

	weekLink = week;
	
	week = week.replace(/'/g,"");
	
	w=320
	h=115
	var left_side = screen.width/2 -240;
	
	mySettings = "left="+left_side+",top=0,height="+eval(h+30)+",width=500,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0"
	
	if(!popUpWin || popUpWin.closed)
		popUpWin = window.open('', 'messages', mySettings)
	else {
		if(!popUpFail) {
			popUpWin.close();
			popUpWin = window.open('', 'messages', mySettings)
		}
	}

	if(!popUpWin || popUpWin.closed) {
		popUpFail = true;
		var tmp = document.getElementById('testMe');
		var clickevent=document.createEvent("MouseEvents")
		clickevent.initEvent("click", true, true)
		tmp.dispatchEvent(clickevent)
	}

	popUpWin.resizeTo(540,370)

	with(popUpWin.document) {
		write('<title>'+week+'<\/title>')
		write('<body bgcolor="#888888">')
		write('<object width="520" height="300" id="wimpy" align="center" type="application/x-shockwave-flash" data="http://www.harvestokc.com/multimedia/wimpy.swf?wimpyReg=NSU3RCUzQ0IlMkElMjhpTTYlN0ZJTGp4ZWI1VEpQNCU1RHElMjZFa3VyNiU3QiUyOUpF&wimpyApp=http://www.harvestokc.com/multimedia/'+week+'.xml&wimpySkin=http://www.harvestokc.com/multimedia/skin_itune.xml&wW=520&wH=300&defaultVisualExt=jpg&theVolume=100&bufferAudio=0&getMyid3info=yes&infoDisplayTime=3&iTextStyle=scroller&popUpHelp=yes&startPlayingOnload=yes">')
		write('<param name="allowScriptAccess" value="sameDomain" />')
		write('<param name="movie" value="http://www.harvestokc.com/multimedia/wimpy.swf" />')
		write('<param name="loop" value="false" />')
		write('<param name="menu" value="false" />')
		write('<param name="quality" value="high" />')
		write('<param name="scale" value="noscale" />')
		write('<param name="salign" value="lt" />')
		write('<param name="bgcolor" value="#888888" />')
		write('<param name="flashvars" value="wimpyReg=NSU3RCUzQ0IlMkElMjhpTTYlN0ZJTGp4ZWI1VEpQNCU1RHElMjZFa3VyNiU3QiUyOUpF&wimpyApp=http://www.harvestokc.com/multimedia/'+week+'.xml&wimpySkin=http://www.harvestokc.com/multimedia/skin_itune.xml&wW=520&wH=300&defaultVisualExt=jpg&theVolume=100&bufferAudio=0&getMyid3info=yes&infoDisplayTime=3&iTextStyle=scroller&popUpHelp=yes&startPlayingOnload=yes" />')
		write('<\/object>')
		write('<\/body>')
		}
		return;
	}

function openOnDemand() {

	var left_side = screen.width/2 - 728/2;

	mySettings = "'left="+left_side+",top=0,height=662,width=728,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0'"

	if(!popUpWin || popUpWin.closed)
		popUpWin = window.open('', 'messages', mySettings)
	else {
		if(!popUpFail) {
			popUpWin.close();
			popUpWin = window.open('', 'messages', mySettings)
		}
	}
		
	if(!popUpWin || popUpWin.closed) {
		popUpFail = true;
		var tmp = document.getElementById('testMe');
		var clickevent=document.createEvent("MouseEvents")
		clickevent.initEvent("click", true, true)
		tmp.dispatchEvent(clickevent)
	}
	
	popUpWin.location = "http://www.ustream.tv/channel-popup/harvestweekend";
}

function openWinVideo(week) {

	weekLink = week;

	if(week == "WebCasting") {
		w=380
		h=360
		w2=w-10
		h2=h-60
	} else {
		w=640
		h=505
		w2=w
		h2=h
	}
	
	var left_side = screen.width/2 - w/2;
		
	mySettings = "'left="+left_side+",top=0,height="+eval(h + 100)+",width=640,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0'"

	if(!popUpWin || popUpWin.closed)
		popUpWin = window.open('', 'messages', mySettings)
	else {
		if(!popUpFail) {
			popUpWin.close();
			popUpWin = window.open('', 'messages', mySettings)
		}
	}
		
	if(!popUpWin || popUpWin.closed) {
		popUpFail = true;
		var tmp = document.getElementById('testMe');
		var clickevent=document.createEvent("MouseEvents")
		clickevent.initEvent("click", true, true)
		tmp.dispatchEvent(clickevent)
	}


	if (navigator.plugins && navigator.plugins.length)
		popUpWin.resizeTo(w+13,h+87)


	with(popUpWin.document) {
		write('<title>'+week+'<\/title>')
		write('<body bgcolor="#888888">')
		write('<object style="position:absolute;top:2;left:2;" width="'+w2+'" height="'+h2+'" id="wimpy" align="center" type="application/x-shockwave-flash" data="http://www.harvestokc.com/flash/harvestPlayer.swf?videoPath=http://www.harvestokc.com/multimedia/video/'+week+'.xml">')
		write('<param name="allowScriptAccess" value="sameDomain" />')
		write('<param name="movie" value="http://www.harvestokc.com/flash/harvestPlayer.swf?videoPath=http://www.harvestokc.com/multimedia/video/'+week+'.xml" />')
		write('<param name="loop" value="false" />')
		write('<param name="menu" value="false" />')
		write('<param name="quality" value="high" />')
		write('<param name="scale" value="noscale" />')
		write('<param name="salign" value="lt" />')
		write('<param name="bgcolor" value="#888888" />')
		write('<\/object>')
		write('<\/body>')
		}
		return;
	}
	
function launchPopup() {
	popUpWin = window.open('', 'messages', mySettings)
}
	
function ieCenter(mySize) {
	if( alertSize() >= mySize ) {
    var newStyle = document.createStyleSheet()
    newStyle.addRule("#container", "height:"+mySize+"px;position:relative;top:50%;")
    newStyle.addRule("#inner", "position:relative;top:-50%;")
  }
}

function alertSize() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}