
$(document).ready(function() {

    // corner fix - for IE
    /*$.uicornerfix = function(r){
		DD_roundies.addRule('.corner-all, .content', r);
	 	DD_roundies.addRule('.corner-right', '0 '+r+' '+r+' 0');
	 	DD_roundies.addRule('.corner-left', r+' 0 0 '+r);
	 	DD_roundies.addRule('.corner-tl', r+' 0 0 0');
		DD_roundies.addRule('.corner-tr', '0 '+r+' 0 0');
		DD_roundies.addRule('.corner-br', '0 0 '+r+' 0');
	 	DD_roundies.addRule('.corner-bl', '0 0 0 '+r);
	};
	$.uicornerfix('6px');*/
	
	// IE6 error message
	if (jQuery.browser.msie && jQuery.browser.version == 6)
	{
		$("#browsererr").html("<div class='error msg'>Stránky nejsou optimalizované pro Internet Explorer 6. Váš prohlížeč je velmi zastaralý. <a href='http://www.microsoft.com/cze/windows/internet-explorer/'>Aktualizujte</a> ho nebo <a href='http://www.google.com/chrome'>nainstalujte</a> jiný.</div>");
	}

    
    // hover class in menu
    $(".menu ul li").hover(function(){$(this).addClass("hover");},function() {$(this).removeClass("hover");})
    
    // fire fancybox
    $("a.fancybox").fancybox();
    $("a.frame").fancybox({ type: 'iframe', width: 700, height: 500 });
    
    // jquery form validation
    $("form.valid").submit(function(e) {
        $(this).children("input.jsinvalid").each(function () {
            alert("Zkontrolujte formulář. Některá pole nejsou vyplněna správně."); e.preventDefault(); return false;
        });
    });
    
    // input validity
    $("input.validate").change(function() {
        rel = $(this).attr("rel");
        val = $(this).val();
        switch (rel) {
            case "name":
                regExp = "^.{5,50}$";
            break;
            case "mail":
                regExp = "^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,5}$";
            break;
            case "num":
                regExp = "^[0-9]*$";
            break;
            default:
                regExp = "^.*$";
        }
        reg = new RegExp(regExp);
        if (reg.test(val)) {
            $(this).removeClass("jsinvalid"); $(this).addClass("jsvalid");
        } else {
            $(this).removeClass("jsvalid"); $(this).addClass("jsinvalid");
        }
    });
    $("input.validate").trigger("change");
    
    // removal for numeral input
    $("input[rel=num], input.num").change(function() {
        val = $(this).val();
        val = val.replace(/[^0-9]/g,"");
        $(this).val(val);
    });
    
    // submit on change
    $(".submitonchange").change(function() {
        $(this).parents("form").submit();
    });
    
    // news appearing
    $(".news-item .news-label").mouseenter(function() {
        $(this).siblings(".news-body").slideDown("slow",function() {
            $(this).siblings(".news-label").addClass("expanded");
            $(".news-item").mouseleave(function() {
                $(this).find(".news-body").slideUp("slow",function() {
                    $(this).siblings(".news-label").removeClass("expanded");
                });
            });
        });
    });
    
    // total price counting
    $("input[name=cupoun_count]").change(function() {
        cupoun_price = $("input[name=cupoun_price]").val();
        total_price = cupoun_price * $(this).val();
        $("#total_price").text(total_price + ' Kč');
    });
    $("input[name=cupoun_count]").trigger("change");
    
    // newsletter subscribe input
    $("input.empty").focus(function() {
        $(this).val('');
        $(this).removeClass('empty');
    });
    

});

