﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;


var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#backgroundPopup").css({
            "opacity": "0.7",
	    "height": "1000px"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup() {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();
    //centering
    $("#popupContact").css({
        "position": "absolute",
        //"top": windowHeight / 2 - popupHeight / 2,
        //"left": windowWidth / 2 - popupWidth / 2 - 100
    });
	//"left": windowWidth / 2 - popupWidth / 2 - 100
    //only need force for IE6

    $("#backgroundPopup").css({
        "height": windowHeight
    });

}



function checkLikeButton() {

    //$("iframe.fb_ltr").contents().find("body").html().css("background-color", "red");
    $('iframe').load(function() {
        $(this.contentDocument).find('body').html('div>test</div>');
    });
    if ($("iframe.fb_ltr a.connect_widget_like_button").hasClass('connect_widget_like_button')) {
        alert("show");
    }
    else {
        alert('no');
    }


}


function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

function setCookie(c_name, value, exdays,path,domain) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value +
    ((path) ? ";path=" + path : "") +
    ((domain) ? "; domain=" + domain : "");
}

function checkCookie() {
    //var chkFan = document.getElementById("chklsshop").checked = false;
    var fan = getCookie("lsshop1");
    //alert(fan);
    if (typeof (fan) == "undefined") {
        //alert('true');
        setCookie("lsshop1", true, 7,"/","lsshop.biz");
        //centering with css
        centerPopup();
        //load popup
        loadPopup();
    }
}

function setlsshopCookie(chkElement) {
    if (chkElement.checked == true) {
        setCookie("lsshop", true, 365);
        //alert('cekirano');
     }
    else {
        setCookie("lsshop", false, 365);
        //alert('necekirano');
    }
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {
    //LOADING POPUP

    //on page load
    //function startPopUp() {

    //setTimeout("checkLikeButton()", 5000);
    checkCookie();
    //}

    //Click the button event!
    $("#button").click(function() {
        //centering with css
        centerPopup1();
        //load popup
        loadPopup1();
    });

    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose").click(function() {
        disablePopup();
    });

    //Click out event!
    $("#backgroundPopup").click(function() {
        disablePopup();
    });
	
    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });

});
