/*****

REQUIREMENTS

1. jquery must be included before this script
2.you must have a div on your page with the id of greyOutHolder
3. you must include greyOutHolder.css or place the styles from there into your global style sheet
4. you must update the variables below to match up to your players path and dimensions
5. You must include SWFObject.



**/
var playerPath = "assets/flash/videoPlayerSml.swf";
var playerWidth = 320;
var playerHeight = 320;
var playerMargin = 20;
var browserType = '';


$(document).ready(function() {
    $.each($.browser, function(i, val) {
        if (i == 'safari' && val == true) { browserType = 'safari'; }
        if (i == 'opera' && val == true) { browserType = 'opera'; }
        if (i == 'msie' && val == true) { browserType = 'msie'; }
        if (i == 'mozilla' && val == true) { browserType = 'mozilla'; }
    });
});


    function greyOut(video_path) {

        
        if (video_path.lastIndexOf("320") == -1) {
            playerPath = "assets/flash/videoPlayerBig.swf";
            playerHeight = 520;
            playerWidth = 640;
        }
	
		//write greyOut
		var content = '<div id="greyOut" ><div id="panel"><div id="player">You need flash player 8 or above to view this movie</div><div id="close_btn"><a onclick="return hideGreyOut();" href="#">Close</a></div></div></div>';
		$("#greyOutHolder").html(content);
		//update styles
		$("#greyOut > #panel").css("width", playerWidth + playerMargin);
		$("#greyOut > #panel").css("height", playerHeight + (playerMargin * 2));
		$("#greyOut > #panel > #player").css("width", playerWidth);

		 //if( video_path.lastIndexOf(".flv") != -1)
		 //{
			 var so = new SWFObject(playerPath,'mpl',playerWidth,playerHeight,'8');
			 so.addParam('wmode','transparent');
			 so.addParam('allowscriptaccess','always');
			 so.addParam('allowfullscreen','true');
			 so.addVariable('height',playerHeight);
			 so.addVariable('width', playerWidth);
			 so.addVariable('videoPath',video_path);
			 so.addVariable('autostart','true');
			 so.write('player');
			 //}
		 if (browserType != 'msie') {
		     $('#greyOut').fadeIn('slow');
		 } else {
		     $('#greyOut').show();
		 }
		//vertically center player
		var viewPortHeight;
		 
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		 
		if (typeof window.innerWidth != 'undefined'){
			viewPortHeight = window.innerHeight
		}
		 
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

		else if (typeof document.documentElement != 'undefined'&& typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
			viewPortHeight = document.documentElement.clientHeight
		}
		 // older versions of IE
		else{
			viewPortHeight = document.getElementsByTagName('body')[0].clientHeight
		}
		var vertPos = (viewPortHeight * 0.5) - (playerHeight / 2);
		$("#panel").css("margin-top",vertPos);
		
		return false;
	}
	
	function hideGreyOut(){
	    if (browserType != 'msie') {
	        $('#greyOut').fadeOut('slow');
	    } else {
	        $('#greyOut').hide();
	        $('div#player').html('');
	    }
	    return false;
	}