// jQuery mod functions
jQuery.fn.center = function() {
    this.css("position", "absolute");
    //this.css("top", ($(window).height() - this.height()) / 2 - $(window).scrollTop() + "px");
	this.css("top", $(window).scrollTop() + 100 + "px");
    this.css("left", ($(window).width() - this.width()) / 2 - $(window).scrollLeft() + "px");
    return this;
}

function getImgSize(imgSrc) {
    var newImg = new Image();
    newImg.src = imgSrc;
    var height = newImg.height;
    var width = newImg.width;
	return width;
}

function loadPlayer(moviepath){	
	
	var html5type = "mp4";
	if ($.browser.webkit) {
		html5type = "mp4";
	}
	if ($.browser.mozilla) {
		html5type = "ogv";
	}
	var hasFlash = swfobject.getFlashPlayerVersion();
	if (hasFlash.major > 0) {
		
		// Set the swfobject data
	    params = {};
	    params.quality = 'high';
	    params.wmode = 'opaque';
	    params.salign = 't';
	    params.allowFullScreen = true;
	    vars = {};
	    vars.videoName = moviepath;
	    //vars.transpath = transpath;
	    swfobject.embedSWF("/swf/flv_player.swf", "modalSWF", "864", "520", "8", "/js/expressInstall.swf", vars, params);
		
	    
	} else {
		
		moviepath = moviepath.replace(/swf/i, html5type);
		moviepath = moviepath.replace(/flv/i, html5type);
		
		$('#modalSWF').html('<div id="non-flash-html5"><video id="non-flash-video" controls="controls" width="864" height="480"  preload="auto"><source id="webkit-movie" src="/swf/FlashAssets/flv/'+ moviepath +'" /></video></div>');
   		document.getElementById('non-flash-video').play();
		$('#modalPlayerWin a.close').bind('click', function() {
			document.getElementById('non-flash-video').pause();
		});	  	
	
	}
   
  }

//Modal Window functions
function launchWindow(id) {
    
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect
    $('#mask').fadeTo("slow", 0.6);
    $('#mask').fadeIn(500);

    //Get the window height and width
    //var winH = $(window).height();
    //var winW = $(window).width();

    //Set the popup window to center
    //$(id).css('top', winH / 2 - $(id).height());
    //$(id).css('left', winW / 2 - $(id).width() / 2);
    $(id).center();
    
    //transition effect
    $(id).fadeIn(2000);
}

function launchSWFWindow(id, src){

	loadPlayer(src);
	
	//Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect
    //$('#mask').fadeTo("slow", 0.6);
    //$('#mask').fadeIn(500);
    //$('#mask').show();
    
    //Get the window height and width
    //var winH = $(window).height();
    //var winW = $(window).width();

    //Set the popup window to center
    //$(id).css('top', winH / 2 - $(id).height());
    //$(id).css('left', winW / 2 - $(id).width() / 2);
    $(id).center();
    
    //transition effect
    //$(id).fadeIn(2000);
    $(id).show();
}

function launchIMGWindow(id, src, link){
   
    $(id + ' #modalIMG').html('<a href="'+ link +'"><img class="modal-image" src="" /></a>');
	
	$(id + ' #modalIMG img.modal-image').attr('src', src).load(function() {  
        
		imgWidth = getImgSize(src);
		
		$(id + ' #modalContent').css("width", imgWidth);	
	    $(id + ' #modalIMG').css("width", imgWidth);
		
		//Get the screen height and width
	    var maskHeight = $(document).height();
	    var maskWidth = $(window).width();
	
	    //Set heigth and width to mask to fill up the whole screen
	    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });
	
	    //transition effect
	    $('#mask').fadeTo("slow", 0.6);
	    $('#mask').fadeIn(500);
	
	    //Get the window height and width
	    //var winH = $(window).height();
	    //var winW = $(window).width();
	
	    //Set the popup window to center
	    //$(id).css('top', winH / 2 - $(id).height());
	    //$(id).css('left', winW / 2 - $(id).width() / 2);
	    $(id).center();
	    
	    //transition effect
	    $(id).fadeIn(2000);
	
	});
}
