﻿var GlobalPopupId = false;
window.onerror = function() { return false; }
$(document).ready(function() {
    
    $("#grand-prize, #second-prize, #third-prize, #makeover-rules, #home-details-rules").each(function(i) {
        $(this).click(function() {
            var windowWidth   = document.documentElement.clientWidth;
            var windowHeight  = document.documentElement.clientHeight;
            var popid, targid = $(this).attr('id');
            switch(i) {
                case 0: case 1: case 2: popid = targid.replace('prize','popup'); break;
                    default: popid = 'rules-popup'; break;
            }
            
            var height = $('#'+popid).height();
            var width  = $('#'+popid).width();
            
            GlobalPopupId = popid;
            $('#'+popid).css({
                "position": "absolute",
                 "top": (windowHeight / 2) - (height / 2),
                "left": (windowWidth / 2)  - (width / 2)
            }).fadeIn(500);
            
            if (popid == 'rules-popup')
            {
                try { $('div#rules-popup .scroll').jScrollPane({ showArrows: true, scrollbarWidth: 14 }); }
                    catch (e) { }
            }
            $('.popupbkg').css('opacity','0.7').css('display','block');
        });            
    });
    
    $('.popup-close, .popupbkg').click(function() { 
        $('#'+GlobalPopupId).fadeOut(500); GlobalPopupId = false;
        if ($('.popupbkg').length > 0)
            $('.popupbkg').fadeOut(500);
    });    
    $('.popupbkg').css({ "height": document.documentElement.clientHeight });    
}); 