$(window).bind("load",function(){
    $(".pngFix").not(".hidden").show();
    $(".inlineFix").css("display","inline").removeClass("inlineFix");
    $(".kategorija_link, .button_link").not(".hidden").css("display","block");
    if (jQuery.browser.msie && jQuery.browser.version == "6.0")
        $(".ieInlineFix").css("display","inline").removeClass("ieInlineFix");
    $("img.checkboxoff").hide();
     setTimeout(hideCartEmptyMessage,5000);
    $(".centerFix").each(function(){
        var width = 0;
        $(this).children().not(".clear").each(function(){
            width += $(this).outerWidth(true);
        });
        margin = ($(this).outerWidth()-width)/2;
        $(this).css({"padding-left":margin+"px"});
    });
    $(".styledSelect").sSelect({ddMaxHeight: '150px'});
    $(".hidden").hide();

});

$(document).bind("ready",function(){
    $("#javascriptWarning").remove();
    $("input[htmlName=cardNumber], input[htmlName=cardExpiration], input[htmlName=cardCVD]").val("");

    $(".textFieldHolderW1, .textFieldHolderW2").click(function(){
        $(this).children("input:first").focus();
    });
    
    $(".headerButtonHolder").hover(
        function(){
            if ($(".headerButtonRight",this).length>0)
                $(this).removeClass("headerButtonHolder").addClass("headerButtonHolderActive");
        },function(){
            if ($(".headerButtonRight",this).length>0)
                $(this).removeClass("headerButtonHolderActive").addClass("headerButtonHolder");
        })
    
//    $(".transparent50").fadeTo(1, 0.50);

    
    $("input[formName]:text, input[formName]:password").live("keydown",function(e){
        if (e.keyCode==13){
            e.preventDefault();
            e.stopPropagation();
            $("a[formName="+$(this).attr("formName")+"]").filter(":first").click();
        }
    });
    
    $("div.checkbox").click(function(){
        $(this).children("img").toggle();
    });
    
    
    $("a[formName]").click(function(e){
        e.preventDefault();
        e.stopPropagation();
        if ($(this).attr("clicked") == "true") return;
        $(this).attr("clicked","true");
        var formName = $(this).attr("formName");
        var destination = $(this).attr("href");
        var fields = {};
        var form = $(document.createElement("form"));
        form.attr("method","post")
        form.attr("action",destination);
        
        $("input[formName="+formName+"]").not(":radio").not(":checkbox").add("select[formName="+formName+"]").each(function(){
            var input = $(document.createElement("input"));
            input.attr("type","hidden");
            input.attr("name",$(this).attr("htmlName"));
            input.attr("value",$(this).val());
            form.append(input);
        });
        
        $("input[formName="+formName+"]:checked:radio").each(function(){
            var input = $(document.createElement("input"));
            input.attr("type","hidden");
            input.attr("name",$(this).attr("htmlName"));
            input.attr("value",$(this).val());
            form.append(input);
        });
        
        $("input[formName="+formName+"]:checked:checkbox").each(function(){
            var input = $(document.createElement("input"));
            input.attr("type","hidden");
            input.attr("name",$(this).attr("htmlName"));
            input.attr("value","on");
            form.append(input);
        });        
        
        
        $("<input type='hidden' name='"+formName+"' />").appendTo(form);
        $(document.body).append(form);
        form[0].submit();
    });
    
    $("input[clearSuggestion=1]").focus(function(){
        if ($(this).attr("clearSuggestion")!=1) return true;
        $(this).val("").attr("clearSuggestion","0");
        
    });
    
    $("input[isPassword=1]").focus(function(){
        if ($(this).attr("isPassword")!=1) return true;
        var parent = $(this).parent();
        var novi=$("<input type='password' />")
        novi.attr("htmlName",$(this).attr("htmlName"));
        novi.attr("formName",$(this).attr("formName"));
        novi.attr("name",$(this).attr("name"));
        novi.attr("class",$(this).attr("class"));
        $(this).remove();
        parent.append(novi);
        $(this).attr("isPassword","0");
        novi.focus();
    });
    
    $(".orderLink").click(function(){
        if ($(this).text()==viewDetails) $(this).text(hideDetails);
            else $(this).text(viewDetails)
        $(this).parent().nextAll(".quad_stupac_outer:first").slideToggle();

    });
    
    $(".FAQQuestionHolder").click(function(){

        var answer = $(this).siblings(".FAQAnswerHolder");
        
        if (jQuery.browser.msie && jQuery.browser.version == "6.0")
        {
            $(".FAQAnswerHolder:visible").not(answer).hide();
            answer.show();
        }
        else
        {
            $(".FAQAnswerHolder:visible").not(answer).slideUp();
            answer.slideDown();
        }
        
        $(".FAQQuestionHolderSelected").hide();
        $(".FAQQuestionHolder").show();
        
        $(this).siblings(".FAQQuestionHolderSelected").show();
        $(this).hide();
    });
    
    $(".subMenuParent").hover(function(){
        $(this).children(".subMenuHolder").show();
    },function(){
        $(this).children(".subMenuHolder").hide();
    });
   
    
});

function hideCartEmptyMessage()
{
$(".cartEmptyHolder").fadeOut(3000);
}

function MM_openBrWindow(theURL,winName,features) { window.open(theURL,winName,features); }
