var badBrowser = (/MSIE ((5\.5)|6|7|8)/.test(navigator.userAgent) && navigator.platform == "Win32"); 
var badBrowser67 = (/MSIE ((5\.5)|6|7)/.test(navigator.userAgent) && navigator.platform == "Win32"); 
var $loading = $('#loading');

var curIndex = 0;

function ladeNaechstesBild() {
    if (curIndex == prodliste.length)
        return;
    var curImg = $('#'+prodliste[curIndex++]);
    curImg.attr("src", curImg.attr("llsrc"));
    curImg.load(function () {
        ladeNaechstesBild();
    });
}

function ladeHS() {
    $('#searchribhs').load('ajalistehs.php?art=hs', function() {
        $('#my-dropdown5').change(function(){
            location.href = "liste.php?hs="+$(this).val();
        });
    });
    /*
    $('#dhtmlgoodies_menu_xx').load('ajalistehs.php?art=tabs', function() {
        if (typeof(menuzwei) == 'undefined') {
            $(".menu_tab_content").hide(); //Hide all content
            $("ul.menutabs li:first").addClass("active").show(); //Activate first tab
            $(".menu_tab_content:first").show(); //Show first tab content
        } else {
            $("#weiterid").addClass("active").show(); //Activate first tab
            $(".menu_tab_content").hide(); //Hide all content
            $("#menutab2").show();
        }
    });
    */
}

function iinit() {
    ladeNaechstesBild();
    if ($('#tab_container_liste .tab_container').length) {
			  $('#tab_container_liste .tab_container').css("overflow", "visible").css("height", "auto");
    }

    var config = {    
        sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)    
        interval: 100,  // number = milliseconds for onMouseOver polling interval    
        over: doOpen,   // function = onMouseOver callback (REQUIRED)    
        timeout: 10,   // number = milliseconds delay before onMouseOut    
        out: doClose    // function = onMouseOut callback (REQUIRED)    
    };
    function doOpen() {
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
        //console.log("doopen");
    }
    function doClose() {
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
        //console.log("doclose");
    }
    //$("ul.sf-menu li").hoverIntent(config);
    //$("ul.sf-menu li ul li:has(ul)").find("a:first").append(" &raquo; ");



    $.tools.validator.localize("de", {
	      "*"			: "Eingabefeld korrigieren",
	      ":email"  	: "E-Mail Adresse eingeben",
	      ":password"  	: "Bitte Passwort eingeben",
	      ":number" 	: "Bitte eine Zahl eingeben",
	      ":url" 		: "Bitte eine g&uuml;ltige URL eingeben",
	      "[max]"	 	: "Bitte eine Zahl kleiner oder gleich als $1 eingeben",
	      "[min]"		: "Bitte eine Zahl gr&ouml;&szlig;er oder gleich $1 eingeben",
	      "[minlength]"		: "Eingabe mu&szlig; mindestens  $1 Zeichen lang sein",
        "[data-equals]" : "Eingabe mu&szlig; mit Eingabe $1 &uuml;bereinstiummen",
	      "[required]"	: "Bitte Feld ausf&uuml;llen"
    });

    $.tools.validator.fn("[data-equals]", function(input) {
	      var name = input.attr("data-equals"),
		        field = this.getInputs().filter("[name=" + name + "]"); 
	      return input.val() == field.val() ? true : [name]; 
    });
    $.tools.validator.fn("[min]", function(input, value) {
        var min = input.attr("min");
        return parseFloat(value) >= parseFloat(min) ;
    });
    $.tools.validator.fn("[minlength]", function(input, value) {
	      var min = input.attr("minlength");
		    return (parseFloat(value.length) >= parseFloat(min)) ? true : { de: "Eingabe mu&szlig; mindestens "+min+" Zeichen lang sein" } ;
    });
    $.tools.validator.fn("[maxlength]", function(input, value) {
	      var min = input.attr("maxlength");
		    return parseFloat(value.length) <= parseFloat(min) ? true : { de: "Eingabe darf maximal "+min+" Zeichen lang sein" } ;
    });
    $.tools.validator.fn("[max]", function(input, value) {
	      var max = input.attr("max");
		    return parseFloat(value) <= parseFloat(max) ;
    });
   
 // WGs anclicken
    var wg_alle = $("#wg_alle").attr("checked");
    $("#wg_alle").click(function() {
        loadingimage();
        if (!wg_alle) {
            $("#wgliste input").checkCheckboxes("");
            $('#content').load("ajaliste.php?wgliste=1&wg_alle=true", function(){
                $('body').attr('id','liste');
                initcontent();
                return false;
            });
        } else {
            $("#wgliste input").unCheckCheckboxes("#wg_alle");
            $('#content').load("ajaliste.php?wgliste=1&wg_alle=false", function(){
                $('body').attr('id','liste');
                initcontent();
                return false;
            });
        }
        wg_alle = !wg_alle;
        return false;
    });

    $("#wgliste input").click(function() {
        var warengruppe = "";
        var $here = $(this);
        if ($here.val() == 'wg_alle')  return(false);
        $("#wgliste input").each(function() {
            warengruppe = warengruppe + "&" + $(this).val() + "=" + $(this).attr("checked");
        });
        loadingimage();
        if (warengruppe) {
            warengruppe =  "?wgliste=1&reload=1"+warengruppe ;
            $('#content').load("ajaliste.php" + warengruppe, function(){
                $('body').attr('id','liste');
                hslistefertig = false;
                initcontent();
                return false;
            });
        }
    });

    // HSs anclicken
    var hs_alle = $("#hs_alle").attr("checked");
    $("#hs_alle").click(function() {
        loadingimage();
        if (!hs_alle) {
            $("#hsliste input").checkCheckboxes("");
            $('#content').load("ajaliste.php?hsliste=1&hs_alle=true", function(){
                $('body').attr('id','liste');
                initcontent();
                return false;
            });
        } else {
            $("#hsliste input").unCheckCheckboxes("#hs_alle");
            $('#content').load("ajaliste.php?hsliste=1&hs_alle=false", function(){
                $('body').attr('id','liste');
                initcontent();
                return false;
            });
        }
        hs_alle = !hs_alle;
        return false;
    });

    $("#hsliste input").click(function() {
        var warengruppe = "";
        var $here = $(this);
        if ($here.val() == 'hs_alle')  return(false);
        $("#hsliste input").each(function() {
            warengruppe = warengruppe + "&" + $(this).val() + "=" + $(this).attr("checked");
        });
        loadingimage();
        if (warengruppe) {
            warengruppe =  "?hsliste=1&reload=1"+warengruppe ;
            $('#content').load("ajaliste.php" + warengruppe, function(){
                $('body').attr('id','liste');
                initcontent();
                return false;
            });
        }
    });

    $('#sort').change(function(){
        location.href = "liste.php?sort="+$(this).val();
    });
    $('#count').change(function(){
        location.href = "liste.php?count="+$(this).val();
    });

    // Für Listen
	  //Default Action
    if (typeof(hslistefertig) == "undefined" ) {
        hslistefertig = false;
    }
    if (typeof(verflistefertig) == "undefined" ) {
        verflistefertig = false;
    }

    //console.log(hslistefertig+  verflistefertig);
    if (hslistefertig) {
        $("ul.tabs li").removeClass("active");
        $(".tab_container div").hide();
        $("a[hash=#tabhs]").parent().addClass("active");
        $("#tabhs").show();
    }

    if (hslistefertig == false && verflistefertig == false) {
	      $(".tab_content").hide(); //Hide all content
        var $first = $("ul.tabs li:first");
	      $first.addClass("active").show(); //Activate first tab
        var activefirst = $first.find("a").attr("href");
        $(activefirst).show();
    }

	  //On Click Event
	  $("ul.tabs li").click(function() {
		    $("ul.tabs li").removeClass("active"); //Remove any "active" class
		    $(this).addClass("active"); //Add "active" class to selected tab
		    $(".tab_content").hide(); //Hide all tab content
		    var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		    $(activeTab).show(); //Fade in the active content
		    return false;
	  });
	  
	  //When page loads...für Login Tabs
	  $(".tab_content_choose_login").hide(); //Hide all content
	  $("ul.tabs_choose_login li:first").addClass("active").show(); //Activate first tab
	  $(".tab_content_choose_login:first").show(); //Show first tab content
	  
	  //On Click Event für Login Tabs
	  $("ul.tabs_choose_login li").click(function() {
		    $("ul.tabs_choose_login li").removeClass("active"); //Remove any "active" class
		    $(this).addClass("active"); //Add "active" class to selected tab
		    $(".tab_content_choose_login").hide(); //Hide all tab content
		    var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		    $(activeTab).show(); //Fade in the active content
		    return false;
	  });
		
    // Für Menü rechts
    
	  //grosses Menü links
	  $("ul.menutabs li").click(function() {
		    $("ul.menutabs li").removeClass("active"); //Remove any "active" class
		    $(this).addClass("active"); //Add "active" class to selected tab
		    $(".menu_tab_content").hide(); //Hide all tab content
		    var activeMenuTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		    $(activeMenuTab).show(); //Fade in the active content
		    return false;
	  });




}

   
function loadingimage() {
    return;
    //console.log("loadingimage ");
    var $window = $(window);
    var $halbehoehe =  Math.ceil($window.height() / 2);
    var $halbebreite =  Math.ceil(($window.width() - 115) / 2);
    var $scrolledto = $window.scrollTop();
    var $scrolledleft = $window.scrollLeft();

    //console.log("top "+$halbehoehe+" "+$scrolledto+"px left "+$halbebreite+" "+$scrolledleft+"px "+$loading.html());
    /*
    if (loading.length) {
        $loading.css('display', "block");
    }
    */
}
function initcontent() {
    iinit();
}
function ersetzeartliste() {
    if (artliste) {
        //$('#maincol_start').html(artliste).fadeTo('fast', 1);
        $('#content').html("");
        $('#content').html(artliste);
    }

    $('body').attr('id','liste');
    
    iinit();
    if ($loading.length) {
        $loading.hide();
    }

    //console.profileEnd();
    
}

$(document).ready(function(){
    ladeHS();
    iinit();
    if (!badBrowser67) {
    }
});

/*
 *
 * Copyright (c) 2006-2008 Sam Collett (http://www.texotela.co.uk)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * Version 2.1
 * Demo: http://www.texotela.co.uk/code/jquery/checkboxes/
 *
 * $LastChangedDate: 2009-02-07 23:54:23 +0000 (Sat, 07 Feb 2009) $
 * $Rev: 6184 $
 */
;(function(d){d.fn.toggleCheckboxes=function(a,b){a=a||"*";b=b||false;var c=d([]);this.each(function(){var e=d("input[type=checkbox]",this).filter(a).each(function(){this.checked=!this.checked}).filter(":checked");c=e});if(!b){c=this}return c};d.fn.checkCheckboxes=function(a,b){a=a||"*";b=b||false;var c=d([]);this.each(function(){var e=d("input[type=checkbox]",this).filter(a).each(function(){this.checked=true}).filter(":checked");c=e});if(!b){c=this}return c};d.fn.unCheckCheckboxes=function(a,b){a=a||"*";b=b||false;var c=d([]);this.each(function(){var e=d("input[type=checkbox]",this).filter(a).each(function(){this.checked=false}).filter(":not(:checked)");c=e});if(!b){c=this}return c};d.radioCheckboxGroup=function(e,a){a=a||"*";var b="input[type=checkbox]";if(e){b+="[name="+e+"]"}var c=d(b).filter(a);c.click(function(){c.not(this).each(function(){this.checked=false}).end()})}})(jQuery);

