var lightBoxDict = new Array();

$(document).ready(function(){
 
    function myokfunc(){
    }

    $('.sendToFriend').click(function (e) {
        e.preventDefault();
        // load the contact form using ajax
        $.get(url + "inc/sendfriend.php?product="+window.location, function(data){
            // create a modal dialog with the data
            $(data).modal({
                closeHTML: "<a href='#' title='' class='modalCloseX simplemodal-close'>x</a>",
                position: ["10%",],
                overlayId: 'contact-overlay',
                containerId: 'contact-container',
                onOpen: contact.open,
                onShow: contact.show,
                onClose: contact.close
            });
        });
    });
			 	 
    $('.availability').click(function (e) {
        e.preventDefault();
        // load the contact form using ajax
        var code = $('.kod').html();
        codeElems = code.split(':');
        $.get(url + "inc/ajax/checkAvailability.php?product="+window.location+'&code='+codeElems[1], function(data){
            // create a modal dialog with the data
            $(data).modal({
                close: false,
                overlayId: 'contact-overlay',
                containerId: 'contact-container',
                onOpen: availability.open,
                onShow: availability.show,
                onClose: availability.close
            });
        });
    });

    $('.availabilityRapr').click(function (e) {
        e.preventDefault();

        var product=$(this).find('input').attr("value");
        $.get("../inc/ajax/checkAvailabilityRapr.php?product="+product, function(data){
            // create a modal dialog with the data
            $(data).modal({

                close: false,
                overlayId: 'contact-overlay',
                containerId: 'contact-container',
                onOpen: availability.open,
                onShow: availability.show,
                onClose: availability.close
            });
        });
    });

    var acDivs = ["menuCont", "centerMENUCont", "schranka", "basketId",
    "infoBox", "log", "glossatyList", "ANKETA", "NEWS", "NEWSL",
    "quickContact", "productHistory", "currencyCalc", "categoryHistory",
    "actionProducts", "newProducts", "monitoredProducts", "mostWantedProducts",
    "recommendProducts", "saleProducts", "specSearch", "catDownl", "pay",
    "tagClouds", "menuDes", "seoCategory"];

    $.each(acDivs, function(i, value) {
        animatedcollapse.addDiv(value, "fade=0");
    });
        
    try {
        animatedcollapse.init();
    }
    catch(e) {
    }
    pageReloadBlock();
    
    $.each(acDivs, function(i, value) {
        var aLink = $("a[rel^=" + value + "]");

        if (aLink.size() > 0) {
            if ($("#" + value).is(":visible")) {
                $(aLink).addClass("open");
                $(aLink).removeClass("close");
                $(aLink.parents("div")[0]).find("> div.hideAlt").hide();
            }
            else {
                $(aLink).addClass("close");
                $(aLink).removeClass("open");
                $(aLink.parents("div")[0]).find("> div.hideAlt").show();
            }

            if (value != 'centerMENUCont') {
				aLink.parent().click(function(evt){
					if (!$("#" + value).is(":visible") && $(aLink).hasClass("close")) {
						checkHideBlock(value);
					}
				});
			}
        }
    });

    $(".delivery_date").datepicker({
        changeFirstDay: false,
        showOn: "both",
        buttonImage: "images/calendar.png",
        buttonImageOnly: true,
        onSelect: function (input, date) {
            changeDeliveryDate(input, date);
        }
    });

    $(".jCarouselLite").jCarouselLite({
        //auto: 1000,
        btnNext: ".nextScr",
        btnPrev: ".prevScr",
        mouseWheel: true,
        visible: 5
    });

    // Hide podkladoveho textu u input boxu
    var active_color = "#222"; // Colour of user provided text
    var inactive_color = "#989796"; // Colour of default text
    $("input.value").css("color", inactive_color);
    var default_values = new Array();
    $("input.default").focus(function() {
        if (!default_values[this.id]) {
            default_values[this.id] = this.value;
        }
        if (this.value == default_values[this.id]) {
            this.value = "";
            this.style.color = active_color;
        }
        $(this).blur(function() {
            if (this.value == '') {
                this.style.color = inactive_color;
                this.value = default_values[this.id];
            }
        });
    });

    // JS strankovani
    JPager.init();

    // Password login check
    $("#log").submit(function(evt) {
        return Login.login();
    });    

     $("#loading").bind("ajaxSend", function(){
/*
         ajaxTimer = setTimeout(function() {
            loading(true);
         }, 400);
*/
         loading(true);
     });
     $("#loading").bind("ajaxComplete", function(){
//         clearTimeout(ajaxTimer);
         loading(false);
     });

    $('.prevScr img').hover(function(){
		$(this).attr('src','themes/default/img/img-roller-left-hover.png');
	},function(){
		$(this).attr('src','themes/default/img/img-roller-left.png');
	})
	
	$('.nextScr img').hover(function(){
		$(this).attr('src','themes/default/img/img-roller-right-hover.png');
	},function(){
		$(this).attr('src','themes/default/img/img-roller-right.png');
	})
	
	//$('#loginpassword_off').dPassword({form:$('#log')});
	
	
	showPWHelper();
	$('#loginpassword_helper').focus(function(){
		hidePWHelper(1);
	});
	$('#loginpassword_helper').click(function(){
		hidePWHelper(1);
	});
	$('#loginpassword_helper').change(function(){
		hidePWHelper(1);
		return false;
	});
	$('#loginpassword').focus(function(){
		hidePWHelper(0);	
	});
	$('#loginpassword').blur(function(){
		if($('#loginpassword').val() == '')
			showPWHelper();	
	});
	$('#loginpassword').change(function(){
		if($('#loginpassword').val() == '')
			showPWHelper();	
	});
	
});

