//var frameSource = "View/OverlayVideo.html";
var width = "500";
var height = "400";
function initialize(){
	document.body.setAttribute('id',"sunKINGOverlayFeature");
	addElement();
};


var flashMovie;
/////////////set up the flash interface functionality//////////////////
$(document).ready(function(){
	flashMovie = thisMovie("mymovie");
	   
	function thisMovie(movieName) {
	   
	   if (navigator.appName.indexOf("Microsoft") != -1)
    	{
        	return window[movieName];
    	}
    	else
    	{
        	return document[movieName];
    	}
	
	}
});
//////////////////////////////////////////////////////////////////////


function addElement() {
  var bodyFeature = document.getElementById('sunKINGOverlayFeature');
  var newdiv = document.createElement('div');
  newdiv.setAttribute('id','sunKINGOverlay');
  bodyFeature.appendChild(newdiv);
}
function setOverlayDimensions() {
	var queryString = url.replace(/^[^\?]+\??/,'');
	var params = tb_parseQuery( queryString );
	SK_Width = (params['width']*1) + 30 || 500;
	SK_Height = (params['height']*1) + 40 || 300;
};
function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
};

//DEFAULTS TO PEAR COMMERCIAL
function commercials() {
	 	this.frameSource = "View/OverlayVideo.html";
		var source = "poop";
		startOverlay();
};

//DEFAULTS TO CULINARY COMMERCIAL
function culinary2() {
	 	this.frameSource = "View/Culinary2Video.html";
		var source = "poop";
		startOverlay();	
}

//DEFAULTS TO BOTTLECAP/DRESS COMMERCIAL
function bottlecap(){
	 	this.frameSource = "View/BottleCapVideo.html";
		var source = "poop";
		startOverlay();			
}

function behind() {
		this.frameSource = "View/behindTheScenes.html";
		startOverlay();
};

//THIS IS NO LONGER IN USE
function culinary() {
		this.frameSource = "View/culinaryVideo.html";
		startOverlay();
};

//POPS THE CONTACT FORM
function aiForm(cidVal, sourceVal) {
		createFormOverlay(cidVal, sourceVal);
		$('.OverlayContent').css('width','965px').css('height','600px').css('background','#FFF');
		$('#sunKINGOverlay').fadeIn(400).css('visibility','visible').css('background','none');
};

function aiFormChat(cidVal, sourceVal) {
		//this.frameSource = "http://downloads.sunkingportal.com/EDMC/AiForm/index.html";
		createFormOverlayPostClick(cidVal, sourceVal);
		$('.OverlayContent').css('width','965px').css('height','600px').css('background','#FFF');
		$('#sunKINGOverlay').fadeIn(400).css('visibility','visible').css('background','none');
};


function startOverlay() {
	createOverlay();
	$('.OverlayContent').css('width','700px').css('min-height','200px');
	$('#sunKINGOverlay').fadeIn(400).css('visibility','visible');
};
function closeOverlay() {
	$('#sunKINGOverlay').fadeOut(10);
	$('#flashReplacement').css('visibility','visible').css('display','');
	//turn off topnav button within flash
	flashMovie.closeThickBoxVideo_fl();
	//var callResult = document.getElementById['mymovie'].closeThickBoxVideo_fl();
};


function createFormOverlay(cidVal, sourceVal) {
	
	
	txt='<div class="OverlayContent" id="curvy">';
	txt+='<a onclick="closeOverlay();" class="close"></a><p class="closeText" onclick="closeOverlay();">Return To Site</p>';
	txt+='<div id="contentFeature"><iframe src="http://www.artinstitutes.edu/inspire/default.aspx?'+ cidVal + '&' + sourceVal + '" width="960" height="598" scrolling="no" frameborder="0"></iframe></div>';
	//http://www.artinstitutes.edu/requestinformation/default.aspx?source=TVLOC&cid=NEWTVRIF_CR_087_ST_001
	//txt+='<div id="contentFeature"><iframe src="http://aiimedia.com/_TESTING/testPOP.html" width="960" height="598" scrolling="no" frameborder="0"></iframe></div>';
	txt+='</div>';
	document.getElementById('sunKINGOverlay').innerHTML=txt; 
	$('#curvy').corner(); 
	//$("#contentFeature").load(frameSource);
};


function createFormOverlayPostClick(cidVal, sourceVal) {


	txt='<div class="OverlayContent" id="curvy">';
	txt+='<a onclick="closeOverlay();" class="close"></a><p class="closeText" onclick="closeOverlay();">Return To Site</p>';
	txt+='<div id="contentFeature"><iframe src="http://www.artinstitutes.edu/inspire/default.aspx?'+ cidVal + '&' + sourceVal + '" width="960" height="598" scrolling="no" frameborder="0"></iframe></div>';
	//http://www.artinstitutes.edu/requestinformation/default.aspx?source=TVLOC&cid=NEWTVRIF_CR_087_ST_001
	txt+='</div>';
	document.getElementById('sunKINGOverlay').innerHTML=txt; 
	$('#curvy').corner(); 
	//$("#contentFeature").load(frameSource);
};


document.onkeydown = function(e){ 	
	if (e == null) {
		keycode = event.keyCode;
	} else {
		keycode = e.which;
	}
	if(keycode == 27){
		closeOverlay();
	}
};
function createOverlay() {
	txt='<div class="OverlayContent" id="curvy">';
	txt+='<a onclick="closeOverlay();" class="close"></a><p class="closeText" onclick="closeOverlay();">Close</p>';
	txt+='<div id="contentFeature"></div>';
	txt+='</div>';
	document.getElementById('sunKINGOverlay').innerHTML=txt; 
	$('#curvy').corner(); 
	$("#contentFeature").load(frameSource);
};

//function toggleVideoSource() {
//	switch(videoType) {
//			
//	}
//};

$(document).ready(function(){
	initialize();
	}
);