


$(document).ready(function() {

		$("#matPS").change(function() {
			if($("#matPS").is(":checked")) {
				$("#PS").val(1);
			} else {
				$("#PS").val(0);
			}
		});
		
		$("#matPET").change(function() {
			if($("#matPET").is(":checked")) {
				$("#PET").val(1);
			} else {
				$("#PET").val(0);
			}
		});		


        $("a.fancybox").fancybox({
            'type':'image',
            'overlayShow': 'true'
        });

        if ($("#productSearchForm").length)
        {
            ajaxProductSearch();
        }
        
        $("#productSearchForm input").change(function() {
            ajaxProductSearch();
        });
        $("#productSearchForm select").change(function() {
            ajaxProductSearch();
        });
        

        var totalHeight = ($("#positionContainer").height());
        $("#shadowLeft").css({height: totalHeight} );
        $("#shadowRight").css({height: totalHeight} );

        alignMenu();
        $(window).resize(function(){
           alignMenu();
        });


        $(".navBtn").hover(function() {

            if (this.id == "navProduct")
                {
                    showDropdown($("#dropProduct"), $("#" + this.id));
                    //hideDropdown($("#subSpecialities"));
                }
            else
                {
                    hideDropdown($("#dropProduct"), $("#navProduct"));
                    //hideDropdown($("#subSpecialities"));
                }

            if (this.id =="navCompany")
                {
                    showDropdown($("#dropCompany"), $("#" + this.id));
                }
             else
                {
                    hideDropdown($("#dropCompany"), $("#navCompany"));
                }
            if (this.id == "navBenefit")
                {
                    showDropdown($("#dropBenefit"), $("#" + this.id));
                }
            else
                {
                    hideDropdown($("#dropBenefit"), $("#navBenefit"));
                }
            if (this.id == "navEnvironment")
                {
                    showDropdown($("#dropEnvironment"), $("#" + this.id));
                }
            else
                {
                    hideDropdown($("#dropEnvironment"), $("#navEnvironment"));
                }
             if (this.id == "navNews")
                 {
                     showDropdown($("#dropNews"), $("#" + this.id));

                 }
             else
                 {
                     hideDropdown($("#dropNews"), $("#navNews"));
                 }

        });

        $(".subBtn").hover(function() {
               /*if ($("#dropProduct").css("opacity")>0.0)
                  {
                        if (this.id == "btnSpecialities")
                        {
                           showDropdown($("#subSpecialities"), specHeight, 150);
                           $("#btnSpecialities").addClass("active");
                        }
                        else
                        {
                            hideDropdown($("#subSpecialities"));
                            $("#btnSpecialities").removeClass("active");
                        }
                  }*/
          } );

        $("#contentLeft").click(function() {
           hideAll();
        });
        $("#headerContainer").click(function(){
           hideAll();
        });

        $(".containerContent").click(function() {
            //hideSearchForm();
        });
        $("#headerContainer").click(function() {
            //hideSearchForm();
        });

        $(window).keydown(function(e) {
            if (e.keyCode == "27")
            {
               // hideSearchForm();
            }
        });
});

function ajaxProductSearch()
{
   $("#ajaxResult").html("<img src='img/ajax-loader.gif' />");
            
            $.ajax({
                   type: "POST",
                   url: "index.php?mode=ajaxProductSearch&lang=" + $("#language").val(),
				   data: $("#productSearchForm").serialize()
                   /*data: "econopack=" + $("#econopack").is(":checked") +
                        "&supersell=" + $("#supersell").is(":checked") +
                        "&showcase=" + $("#showcase").is(":checked")+
                        "&traypack=" + $("#traypack").is(":checked")+
                        "&jumbotherm=" + $("#jumbotherm").is(":checked")+
                        "&starpack=" + $("#starpack").is(":checked")+
                        "&specialities=" + $("#specialities").is(":checked")+
                        "&packageSize=" + $("#eggSize").val() +
                        "&eggWeight=" + $("#eggWeight").val() +
                        "&PS=" + $("#matPS").is(":checked") +
                        "&PET=" + $("#matPET").is(":checked")*/,

                   success:function(html) {
                       $("#ajaxResult").html(html);
                       alignMenu();
                   }
           });                     
}

function alignMenu()
{  
    var xDropCompany = $("#navCompany").position().left; //64;    
    var xDropProduct = $("#navProduct").position().left;
    var xDropBenefit = $("#navBenefit").position().left;
    var xDropEnvironment = $("#navEnvironment").position().left;
    var xDropNews = $("#navNews").position().left;

    //var position = $("#positionContainer").position();

    $("#dropCompany").css({"left" : (xDropCompany) + "px"});
    $("#dropProduct").css({"left" : (xDropProduct) + "px"});
    $("#dropBenefit").css({"left" : ( xDropBenefit) + "px"});
    $("#dropEnvironment").css({"left" : ( xDropEnvironment) + "px"});
    $("#dropNews").css({"left": (xDropNews) + "px"});

    //shadows
    
    $("#shadowLeft").css("height", $("#containerFooter").position().top + $("#containerFooter").height() +4);
    $("#shadowRight").css("height", $("#containerFooter").position().top + $("#containerFooter").height() +4);

    $("#contentLeft").height("auto", function() {

        if ($("#contentLeft").innerHeight()<$("#contentRight").height())
        {
            $("#contentLeft").height($("#contentRight").height());
        }
    });
}

function hideAll()
{
     hideDropdown($("#dropProduct"), $("#navProduct"));
     hideDropdown($("#dropCompany"), $("#navCompany"));
     hideDropdown($("#dropBenefit"), $("#navBenefit"));
     hideDropdown($("#dropEnvironment"), $("#navEnvironment"));     
     hideDropdown($("#dropNews"), $("#navNews"));
}

function showDropdown($div, $btn)
{
       if (!$div.is(":visible"))
       {
           $div.animate({height:'show', opacity:1.0}, 300);
           $btn.addClass("active");
       }
  
}

function hideDropdown($div, $btn)
 {
     if ($div.is(":visible"))
     {
        $div.animate({height:'hide', opacity: 0.8}, 100);
        $btn.removeClass("active");
     }
     

 }
