// jQuery mod functions
jQuery.fn.center = function() {
    this.css("position", "absolute");
    //this.css("top", (jQuery(window).height() - this.height()) / 2 - jQuery(window).scrollTop() + "px");
    this.css("top", jQuery(window).scrollTop() + 175 + "px");
    this.css("left", (jQuery(window).width() - this.width()) / 2 - jQuery(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;
}

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

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

    //transition effect
    jQuery('#mask').fadeTo("slow", 0.6);
    jQuery('#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);
    jQuery(id).center();
    
    //transition effect
    jQuery(id).fadeIn(1000);
}


function launchHTMLWindow(id, src) {
    
    //Get the screen height and width
    var maskHeight = jQuery(document).height();
    var maskWidth = jQuery(window).width();

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

    //transition effect
    jQuery('#mask').fadeTo("slow", 0.6);
    jQuery('#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);
    jQuery(id).center();
	
	// Get the content and set it in the modal
    var content = jQuery(src).html();
	jQuery(id + " #modalContent").html('');
	jQuery(id + " #modalContent").html(content);
	
    //transition effect
    jQuery(id).fadeIn(1000);
}

function launchSWFWindow(id, src){

    var playerVersion = swfobject.getFlashPlayerVersion(); // returns a JavaScript object
    var majorVersion = playerVersion.major; // access the major, minor and release version numbers via their respective properties
    
    if (majorVersion >= 8) {
       jQuery(id + ' #modalSWF').html('<embed src="'+ src +'" width="425" height="388" allowscriptaccess="always" wmode="opaque" quality="high" bgcolor="#000000" name="'+ id +'-swffile" id="'+ id +'-swffile" style="" type="application/x-shockwave-flash">');
    } else {
       jQuery(id + ' #modalSWF').html('Flash player is not installed');
    }
    //Get the screen height and width
    var maskHeight = jQuery(document).height();
    var maskWidth = jQuery(window).width();

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

    //transition effect
    jQuery('#mask').fadeTo("slow", 0.6);
    jQuery('#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);
    jQuery(id).center();
    
    //transition effect
    jQuery(id).fadeIn(1000);
}

function launchIMGWindow(id, src, link){
   
    jQuery(id + ' #modalIMG').html('<a href="'+ link +'"><img class="modal-image" src="" /></a>');
    
    jQuery(id + ' #modalIMG img.modal-image').attr('src', src).load(function() {  
        
        imgWidth = getImgSize(src);
        
        jQuery(id + ' #modalContent').css("width", imgWidth);    
        jQuery(id + ' #modalIMG').css("width", imgWidth);
        
        //Get the screen height and width
        var maskHeight = jQuery(document).height();
        var maskWidth = jQuery(window).width();
    
        //Set height and width to mask to fill up the whole screen
        jQuery('#mask').css({ 'width': maskWidth, 'height': maskHeight });
    
        //transition effect
        jQuery('#mask').fadeTo("slow", 0.6);
        jQuery('#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);
        jQuery(id).center();
        
        //transition effect
        jQuery(id).fadeIn(1000);
    
    });
}
