$(document).ready(function() {

    var ajxCon = "index.php";

    //////////////////////////////////////////////////////////////
	var shipping_services_disable = function(service_id) {
	$("#zusatz_"+service_id).find("input[type=checkbox]").each(function(index) {
	   if($(this).attr('disabled')) {
	       $(this).attr('disabled', false);
	   } else {
	   	$(this).attr('checked', false);
	       $(this).attr('disabled', true);
	   }
	   });
	};

	// init page start select services
	$(".del_serv_chb1 input[type=checkbox]").not(":checked").each(function(index,item) {
	    shipping_services_disable($(this).attr("id"));
	});

	$(".del_serv_chb1 input[type=checkbox]").click(function() {
	    shipping_services_disable($(this).attr("id"));
	});
/////////////////////////////////////////////////////////////		

    $('.product-switcher').products({
        speed:6000
    });

    $('ul.jcarousel-products').jcarousel({
        visible:4,
        scroll: 4,
        animation: 'slow'
	
    });

    if($.browser.version != 6) {
        $('ul#products-category').jcarousel({
            visible:6
        });
        $('ul#products-category').children().css( 'visibility', 'visible' );
        $('ul.jcarousel-products').children().css( 'visibility', 'visible' );

    }

    $('ul.jcarousel-skin-products').jcarousel({
	visible:4
    });

    $('ul.jcarousel-skin-brands').jcarousel({
	visible:4,
        scroll: 4
    });

    $('ul.jcarousel-manufacturer').jcarousel({
        visible:4,
        vertical: true
    });

    $('ul.products.gallery.jcarousel').jcarousel({
        visible:3
    });
	

    $('#categories').categories();

    $('div.teaser.switchable').teaser();


    $("a[rel=image-zoom]").fancybox();
    $("a[rel=product-image-zoom]").fancybox();
    $("a[rel=lightbox]").fancybox();

    $("a#inline").fancybox({
        'hideOnContentClick': true
    });

    $("a.group").fancybox({
        'speedIn'		:	600,
        'speedOut'		:	200,
        'overlayShow'	:	false
    });


    $(".tab-container").tabs();
    $(".tab-container-service").tabs();

    ////////////////////////////////////////////////////////////////////////////
    /**
	 * Hover Menu
	 *
	 *
	 */
    var activMenuItem;
    var wait;
    var timer;
    var hideMenu = function() {
        $('ul.hover').hide();

        $('#navigation li.active').removeClass('activ');
    };

    var hideMenuItem = function(item) {
        $(item).children('ul.hover').hide();
        $(item).removeClass('active');
    };



    $('#navigation > li').hover(function() {
        var that = $(this);
        wait = window.setTimeout(function() {
            activMenuItem = $(that).attr('id');

            $('#navigation > li').each(function() {
                if($(this).attr('id') != activMenuItem) {
                    hideMenuItem(this);
                }
            });
            var hover = $(that).children('ul.hover');

            $(that).addClass('active');
            clearTimeout(timer);

            $(that).children('ul.hover').bgiframe().show();

            var width = 0;
            hover.children('li:last').addClass('last');

			
        },370)
    }
    ,function() {
        clearTimeout(wait);
        timer = window.setTimeout(hideMenu,500);
    });


    $('.category').each(function(i, item) {
        var href = $(this).find('a:first').attr('href');
        $(this).click(function(){
			
            });
    });

    /**
	 *  List / Gallery View Switcher
	 */
    $('#products-view-list').click(function() {
        if($(this).parent('li').hasClass("active")) {
            return;
        }
        var tempId = $('#temp_id').text();

        $('#products-view-switcher li').removeClass('active');

        $(this).parent('li').addClass('active');
        $('ul.products').removeClass('gallery');
        $('ul.products').addClass('list');
        $.ajax({
            type: "POST",
            url: ajxCon,
            data: "ctrlr=Category&op=setListMode&tempId="+ tempId +"&galleryViewState=1",
            success: function(phpData){

            }
        });

        $('.comparisionLinks').each(function(){
            if($('ul.products').hasClass('list')) {
                var dest= $(this).parent().next().find('.product-mwst');
            } else {
                var dest= $(this).parent().prev().find('.product-availability');
            }
            dest.after(this);
        });
    });
    $('#products-view-gallery').click(function() {
        var tempId = $('#temp_id').text();

        if($(this).parent('li').hasClass("active")) {
            return;
        }


        $('#products-view-switcher li').removeClass('active');
        $(this).parent('li').addClass('active');
        $('ul.products').removeClass('list');
        $('ul.products').addClass('gallery');

        $.ajax({
            type: "POST",
            url: ajxCon,
            data: "ctrlr=Category&op=setListMode&tempId="+ tempId +"&galleryViewState=2",
            success: function(phpData){
            }
        });

        $('.comparisionLinks').each(function(){
            if($('ul.products').hasClass('list')) {
                var dest= $(this).parent().next().find('.product-mwst');
            } else {
                var dest= $(this).parent().prev().find('.product-availability');
            }
            dest.after(this);
        });
    });
    eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(b($j){$j.M=b(){F 14.V||L.1o&&u.O.B||u.A.B};$j.U.R=b(4){3 t=[];3 I=b(e){e.D();3 1=e.m.1;3 6=e.m.6;3 8=e.m.8;3 9=e.m.9;3 q=$j(f).y();3 Q=$j(f).C();3 v=(f.1v||u.O.1r)+$j.M();7(1.d&&(1.d=="1l"||1.d=="1j"||1.d=="G")){f.1g("6."+1.d+"(\'1d\')")}c{6.G()}7(!1.k){1.k=6.y();1.l=6.C()}3 h=e.17-(1.k/2);3 i=e.12-(1.l/2);7(h<0){h=1.g}c 7(h+1.k>q){h=q-1.k-1.g}7(i<0){i=1.g}c 7(i+1.l>v){i=v-1.l-1.g}3 r=11 Z();6.z({"T":h+"x","S":i+"x","W":"X"});7(9){6.Y().P(b(){f.10(r)},b(){r=f.1w(b(){6.N()},8*1t)})}};p.1q(b(){3 o=$j(p).1p("K");7(o&&o.1n(/^#.+/)){3 6=$j(o);7(6.1m>0){3 1=6.1k(0);7(!1.J){t.1h(1);7(4&&4.H){1.g=4.H}c{1.g=5}7(4&&4.E){1.d=4.E}c{1.d=1f}6.1e("a[K^=#][1i=1c]").n(b(e){e.D();6.N()});1.J=w}7(4&&4.9!=1b){3 9=4.9}c{3 9=w}7(4&&4.n&&4.n==w){3 s="n"}c{3 s="1a"}7(4&&4.8&&4.8>0){3 8=4.8}c{3 8=0}$j(p).19(s,{"1":1,"6":6,"8":8,"9":9},I)}}});$j(t).18("A").z({"16":"1s","15":"1u","13":"1x"});F p}})(L);',62,96,'|tooltipE||var|options||tooltip|if|hideDelay|hideOnMouseOut||function|else|_effect||window|_margin|tPosX|tPosY||_width|_height|data|click|currentHref|this|winWidth|timer|showEvent|all_tooltips|document|winYViewLimit|true|px|width|css|body|clientHeight|height|preventDefault|effect|return|show|margin|openTooltip|_tooltipInit|href|jQuery|viewportHeight|hide|documentElement|hover|winHeight|simpletooltip|top|left|fn|innerHeight|cursor|help|unbind|Number|clearTimeout|new|pageY|display|self|zIndex|position|pageX|appendTo|bind|mouseover|null|close|fast|find|false|eval|push|rel|slideDown|get|fadeIn|length|match|boxModel|attr|each|scrollTop|absolute|1000|9999|pageYOffset|setTimeout|none'.split('|'),0,{}))

    $("a.tiplink").simpletooltip({
        effect: "fadeIn"
    });

    
});

function CrossSelling(url_cross) {
	parameter = 'width=730,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes';
	newwin = window.open(url_cross,'CrossSelling',parameter);
	newwin.focus();
}

function checkagb() {
		if(document.basketcheckout.agb.checked) {
				return true;
		} else {
				alert('Bitte lesen und bestätigen Sie erst die AGB!');
				return false;
		}
}
function setCheckbox( product_id )
{
        document.getElementById(product_id).checked = true;
        document.form.submit();
}

function crossSellingShowMoreSwitch(target){
    if ($.browser.msie && $.browser.version == '8.0'){
        //alert("Target: " +  target +" IE:"+$.browser.msie+ " Version: "+$.browser.version);
        $(".c" + target).each(function(i, elem) {
            $(elem).css('display', 'block' );
        });
        $(".b" + target).each(function(i, elem) {
            $(elem).css('display','none');
        });


    } else {
        $(".c" + target).slideDown("slow");
        $(".b" + target).slideUp("slow");
    }

    return false;
}

