// http://www.sohtanaka.com/web-design/inline-modal-window-w-css-and-jquery/

var CLOSE_PATH = "img/close_pop.png";

function PageQuery(q) {
    if (q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if (q) {
        for (var i = 0; i < this.q.split("&").length; i++) {
            this.keyValuePairs[i] = this.q.split("&")[i];
        }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) {
        for (var j = 0; j < this.keyValuePairs.length; j++) {
            if (this.keyValuePairs[j].split("=")[0] == s)
                return this.keyValuePairs[j].split("=")[1];
        }
        return false;
    }
    this.getParameters = function() {
        var a = new Array(this.getLength());
        for (var j = 0; j < this.keyValuePairs.length; j++) {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; }
}
function queryString(key) {
    var page = new PageQuery((window.location.search).toLowerCase());
    return unescape(page.getValue(key.toLowerCase()));
}



$(document).ready(function() {

    //$(".women .hover").attr("style","opacity:1"); // nav bar trick to have one selected... breaks after a mouseover
    //alert(""+document.getElementsByTagName("body").offsetheight);

    //alert((window.location+" ").indexOf(".com/fr/"));
    $('body').append('<div id="fade"></div>');
    if ((window.location + " ").indexOf("=fr") != -1) {
        $('body').append('<div id="popup1" class="popup_block"><iframe src="http://f.chtah.com/s/41/2082455795/052710_ZELLERS_FR_REG.html" width="625" height="600" frameborder="0" scrolling="no" name=" ZellersFRRegistration"></iframe></div>');
    } else {
        $('body').append('<div id="popup1" class="popup_block"><iframe src="http://f.chtah.com/s/41/2082455795/052710_ZELLERS_REG.html" width="625" height="600" frameborder="0" scrolling="no" name=" ZellersRegistration"></iframe></div>');
    }

    $('body').append('<div id="poplightContainer"></div>'); // contains our KVI large images (initially hidden)

    if (!document.getElementById("searchSliderSlideOutFlag")) {
        registerEmphassis(); //add the lightbox effect to all anchor tags with .poplight class
    }

    if ((window.location + " ").indexOf(".com/fr/") != -1) {
        $("a.poplight img").attr("alt", "Be the first to know | e-Newsletter");
        $("a.poplight img").attr("title", "Be the first to know | e-Newsletter");
    } else {
        $("a.poplight img").attr("alt", "Soyez les premiers informÃ©s");
        $("a.poplight img").attr("title", "Soyez les premiers informÃ©s");
    }

});
function registerEmphassis() {

    //When you click on a link with class of poplight and the href starts with a # ... removed this:[href^=#]
    $('a.poplight').click(function() {

        //alert("hello");
        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 = parseInt(dim[0].split('=')[1]) || 'auto'; //Gets the first query string value

        //Fade in the Popup and add close button
        $('#' + popID).fadeIn().css({ 'width': Number(popWidth) }).prepend('<a href="#" class="closeForm"><img src="'+CLOSE_PATH+'" class="btn_close" title="Close Window" alt="Close" /></a>');
		
		    //Close Popups and Fade Layer
    $('a.closeForm, #fade').bind('click', function() { //When clicking on the close or fade layer...
        $('#fade , .popup_block').fadeOut(function() {
            $('a.closeForm').remove();
        }); //fade them both out

        return false;
    });

        //Apply Margin to Popup
        $('#' + popID).css({
            'left': (($('body').width() - $('#' + popID).width()) / 2) + "px",
            'top': "50px"
        });

        //Fade in Background
        //$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
        $('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn(); //Fade in the fade layer 

        return false;
    });



}

