/** **/
$(document).ready( function() {

	//subsidary form submittion
	$(".jqSelectSubmit").change( function(e) {
		$(this).parents('form').submit();
	});

/*auto sizing i-frames??
	$('iframe').load(function() {
	        this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
	});
*/
	$(".jqPopup").click( function(e) {
		e.preventDefault();
		
		popup( $(this).attr("href") );
	});
	
	$(".jqMovieLaunch").click( function(e) {
		e.preventDefault();
		
		if ($("#container").size() == 0) {
			//create container above the first .videos block
			$(".jqVideos:first").before('<div id="container" style="width:440px;"></div>');
		}
		
		createplayer($(this).attr("href"), true);
		window.location.hash = 'top';
	});

});

function createplayer(theFile, go) {
	var so = new SWFObject('/images/flash/mediaplayer.swf','player','535','300','8');
	so.addParam("allowfullscreen","true");
	so.addParam("allowscriptaccess","always");
	so.addParam("wmode","opaque");
	so.addVariable("width",535);
	so.addVariable("height",300);
	so.addVariable('file',theFile);
	so.addVariable('displayheight',450);
	so.addVariable('autostart','true');
	so.write('container');
}

function popup (link, Width, Height){
  if (Width == null){
    Width = 790;
  }
  if (Height == null){
    Height = 500;
  }
	if(window.open) {
		windowPop(link, Width, Height, 'resizable,scrollbars');
	}
}

function windowPop(page,pagew,pageh,features) {

	// features = 'resizable,scrollbars'
	if(features!='') {
		features=','+features
	}
	agent = navigator.userAgent.toLowerCase();
	isMacIE = (agent.indexOf('msie') != -1) && (agent.indexOf('mac') != -1)
	if (isMacIE) {
		pagew -= 16
		pageh -= 16
	}

	window.open(page,'windowPop','width=' + pagew + ',height=' + pageh + features).focus()
}
