// JavaScript Document

var lightPop_pathimg = "img/frameworks/lightPop_close.png";

//When you click on a link with class of poplight and the href starts with a # 
// API: <a href="#?w=500" rel="popup_name" class="poplight">Learn More</a>
// Rel attributes is the ID of div
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size
	
    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value
	
	lightPopLoad(popID, popWidth);
});

//Load a popup by ID and URL
function lightPopLoad(popID, popWidth){

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="lightPop_close"><img src="'+lightPop_pathimg+'" class="lightPop_close" title="Fermer la popup" alt="Close" border="0" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="lightPop_fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#lightPop_fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

	//Set OBJECT in Background
	//$("object").append('<param name="wmode" value="opaque" /></param>');

    return false;
}

//Close Popups and Fade Layer
$('a.lightPop_close, #lightPop_fade, a.lightPop_cancel').live('click', function() { //When clicking on the close or fade layer...
    lightPopClose();
    return false;
});
function lightPopClose(){
	$('#lightPop_fade , .lightPop_popup').fadeOut(function() {
        $('#lightPop_fade, a.lightPop_close').remove();  //fade them both out
    });
}

