// When the DOM is ready, init scripts.
jQuery(function( $j ){

	var w24Loader = new w24_loading();

	$j(document).ready(function(){

		w24_heizkoerper_select(1,'w24-profil-kompaktheizkoerper-aktiv');
		w24_heizkoerper_select(2,'w24-profil-ventil-kompaktheizkoerper-aktiv');
		w24_heizkoerper_select(3,'w24-profil-v-kompakt-mittel-aktiv');
		w24_heizkoerper_select(4,'w24-plan-kompaktheizkoerper-aktiv');
		w24_heizkoerper_select(5,'w24-plan-ventil-kompaktheizkoerper-aktiv');
		w24_heizkoerper_select(6,'w24-plan-v-kompakt-mittel-aktiv');

		w24_heizkoerper_typ_select(1,'w24-hk-typ10-aktiv');
		w24_heizkoerper_typ_select(2,'w24-hk-typ11-aktiv');
		w24_heizkoerper_typ_select(3,'w24-hk-typ21-aktiv');
		w24_heizkoerper_typ_select(4,'w24-hk-typ22-aktiv');
		w24_heizkoerper_typ_select(5,'w24-hk-typ33-aktiv');

		w24_product_view_select();
		w24_product_view_mouseover();

		var art = 0;
		var typ = 0;
		var hoehe = 0;
		var breite = 0;
		



			/* Apply fancybox to multiple items */
			
			$j("a.group").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	600, 
				'speedOut'		:	200, 
				'overlayShow'	:	false
			});
			
			$j("a.grouped_elements").fancybox();
				
			$j("#fancybox-close").mouseover(function(){
				$j(this).html("Fenster schlie&szlig;en");
			}).mouseout(function(){
				$j(this).html("");
			});

		$j('.w24-height').find('select').change(function(){
			hoehe = $j(this).val();
		});

		$j('.w24-width').find('select').change(function(){
			breite = $j(this).val();
		});

		$j('.w24-heizkoerper-bottom-inner-dd-box').find('select').change(function(){
            if(
                !$j(".w24-hk-checkbox-toggle", $j(this).parentsUntil(".w24-heizkoerper-bottom").last())
                    .is(".w24-heizkoerper-checkbox-true")
            )
            {
                return;
            }
            if($j(this).val() != '-'){
                $j(this).css("color","#ff5900");
                $j(this).find('option').css("color","#7a7a72");
                w24temp = $j(this).find('option');
                while( $j(w24temp).val() != $j(this).val() ){
                    w24temp = $j(w24temp).next();
                }
                $j(w24temp).css("color","#ff5900");
                $j(w24temp).next().css("color","#7a7a72");
            }else{
                $j(this).css("color","#7a7a72");
                $j(this).find('option').css("color","#7a7a72");
            };
            if($j(this).parent().parent().parent().parent().find('.w24-height').find('select').val() == '-' || $j(this).parent().parent().parent().parent().find('.w24-width').find('select').val() == '-'){
                $j(this).parentsUntil('.w24-heizkoerper-bottom-inner-product-box').find('.w24-heizkoerper-bottom-inner-product-box-text').show();
                $j(this).parentsUntil('.w24-heizkoerper-bottom-inner-product-box').find('.w24-heizkoerper-bottom-inner-product-box-details').hide();
            }else{
				w24Loader.start();
                $j(this).parentsUntil('.w24-heizkoerper-bottom-inner-product-box').find('.w24-heizkoerper-bottom-inner-product-box-text').hide();
                var box = $j(this).parentsUntil('.w24-heizkoerper-bottom-inner-product-box').find('.w24-heizkoerper-bottom-inner-product-box-details');
                var nobox = $j(this).parentsUntil('.w24-heizkoerper-bottom-inner-product-box').find('.w24-heizkoerper-bottom-inner-product-box-none');
                if (window.location.hostname == 'wicked.local') {
                    var url = 'http://' + window.location.hostname + '/w24/ajax';
                }
                else {
                    var url = 'http://' + window.location.hostname + '/ajax';
                }
				var sup = $j('#w24-hk-sup').val();
                $j.post( url,
                    {amode: 'hzk', art: art, typ: typ, hoehe: hoehe, breite: breite, sup: sup},
                    function(data) {
                        if(data){
                            $j('.w24-heizkoerper-typ-leistung-lieferzeit',box).html(data.leistung + "<br>" + data.lieferzeit);
                            $j('.w24-heizkoerper-typ-preis',box).html(data.preis);
                            $j('.w24-heizkoerper-detail-btn a',box).attr('href','heizkoerper/' + data.url);
                            $j(box).show();
                            $j(nobox).hide();
                        }else{
                            $j(box).hide();
                            $j(nobox).show();
                        }
						w24Loader.end();
                    }, "json"
                );
            }
		});

		$j('.qty').change(function(){
			$j(this).parent().find('.w24-warenkorb-refresh').find('.w24-refresh-btn').css("color","#0099d8")
			$j(this).parent().find('.w24-warenkorb-refresh').find('.w24-refresh-btn').addClass('w24-aktiv');
		});
		$j('.w24-refresh-btn').mouseover(function(){
			$j(this).css("color","#ff5900")
		}).mouseout(function(){
			if($j(this).is('.w24-aktiv')){
					$j(this).css("color","#0099d8")
				}else{
					$j(this).css("color","#7a7a72")
				}
		});

		function w24_heizkoerper_select(i,alt_img){
			$j('.w24-hk-toggle-' + i).click(function(){
				if($j(this).is('.w24-aktiv')){
					w24_remove_aktiv();
					$j(this).removeClass('w24-aktiv');
				}else{
					$j('.w24-heizkoerper-top').removeClass('w24-aktiv');
					w24_remove_aktiv();
					$j(this).addClass('w24-orange');
					$j(this).find('.w24-toggle-img').addClass(alt_img);
					$j(this).addClass('w24-aktiv');
					$j(this).find('.w24-hk-checkbox-toggle').addClass('w24-heizkoerper-checkbox-true');
					$j(this).find('.w24-heizkoerper-checkbox').find('.w24-active').show();
					$j(this).find('.w24-heizkoerper-checkbox').find('.w24-inactive').hide();
					$j('.w24-heizkoerper-hide').show();
					art = i;
				}
			});
		}

		function w24_remove_aktiv(){
			$j('.w24-heizkoerper-top').find('.w24-heizkoerper-checkbox-false').removeClass('w24-heizkoerper-checkbox-true');
			$j('.w24-heizkoerper-top').find('.w24-heizkoerper-top-inner').removeClass('w24-orange');
			$j('.w24-heizkoerper-top').find('.w24-heizkoerper-top-inner').removeClass('w24-aktiv');
			$j('.w24-heizkoerper-top').find('.w24-toggle-img').removeClass('w24-profil-kompaktheizkoerper-aktiv');
			$j('.w24-heizkoerper-top').find('.w24-toggle-img').removeClass('w24-profil-ventil-kompaktheizkoerper-aktiv');
			$j('.w24-heizkoerper-top').find('.w24-toggle-img').removeClass('w24-profil-v-kompakt-mittel-aktiv');
			$j('.w24-heizkoerper-top').find('.w24-toggle-img').removeClass('w24-plan-kompaktheizkoerper-aktiv');
			$j('.w24-heizkoerper-top').find('.w24-toggle-img').removeClass('w24-plan-ventil-kompaktheizkoerper-aktiv');
			$j('.w24-heizkoerper-top').find('.w24-toggle-img').removeClass('w24-plan-v-kompakt-mittel-aktiv');
			$j('.w24-heizkoerper-top-inner').find('.w24-heizkoerper-checkbox').find('.w24-active').hide();
			$j('.w24-heizkoerper-top-inner').find('.w24-heizkoerper-checkbox').find('.w24-inactive').show();
			$j('.w24-heizkoerper-hide').hide();
			$j('.w24-height').find('select').val('-');
			$j('.w24-width').find('select').val('-');
			$j('.w24-heizkoerper-bottom-inner-product-box-text').show();
			$j('.w24-heizkoerper-bottom-inner-product-box-details').hide();
			$j('.w24-heizkoerper-bottom-inner-product-box-none').hide();
		}

		function w24_heizkoerper_typ_select(i,alt_img){
			$j('.w24-hk-typ-toggle-' + i).click(function(){
				if($j(this).is('.w24-aktiv')){
					w24_remove_typ_aktiv();
					$j(this).removeClass('w24-aktiv');
				}else{
					$j('.w24-heizkoerper-bottom-inner-box').removeClass('w24-aktiv');
					w24_remove_typ_aktiv();
					$j(this).find('.w24-heizkoerper-typ').addClass('w24-orange');
					$j(this).find('.w24-toggle-img').addClass(alt_img);
					$j(this).addClass('w24-aktiv');
					$j(this).find('.w24-hk-checkbox-toggle').addClass('w24-heizkoerper-checkbox-true');
					$j(this).find('.w24-heizkoerper-checkbox').find('.w24-active').show();
					$j(this).find('.w24-heizkoerper-checkbox').find('.w24-inactive').hide();
					//if($j(this).parent().find('.w24-height').find('select').val() == '-' || $j(this).parent().find('.w24-width').find('select').val() == '-')
						$j(this).parent().find('.w24-heizkoerper-bottom-inner-product-box').show();
					typ = i;
				}
			});
		}

		function w24_remove_typ_aktiv(){
			$j('.w24-heizkoerper-bottom-inner-box').find('.w24-heizkoerper-checkbox-false').removeClass('w24-heizkoerper-checkbox-true');
			$j('.w24-heizkoerper-bottom-inner-box').find('.w24-heizkoerper-typ').removeClass('w24-orange');
			$j('.w24-heizkoerper-bottom-inner-box').find('.w24-heizkoerper-typ').removeClass('w24-aktiv');
			$j('.w24-heizkoerper-bottom-inner-box').find('.w24-toggle-img').removeClass('w24-hk-typ10-aktiv');
			$j('.w24-heizkoerper-bottom-inner-box').find('.w24-toggle-img').removeClass('w24-hk-typ11-aktiv');
			$j('.w24-heizkoerper-bottom-inner-box').find('.w24-toggle-img').removeClass('w24-hk-typ21-aktiv');
			$j('.w24-heizkoerper-bottom-inner-box').find('.w24-toggle-img').removeClass('w24-hk-typ22-aktiv');
			$j('.w24-heizkoerper-bottom-inner-box').find('.w24-toggle-img').removeClass('w24-hk-typ33-aktiv');
			$j('.w24-heizkoerper-bottom-inner-box').find('.w24-heizkoerper-checkbox').find('.w24-active').hide();
			$j('.w24-heizkoerper-bottom-inner-box').find('.w24-heizkoerper-checkbox').find('.w24-inactive').show();
			$j('.w24-heizkoerper-bottom-inner-product-box').hide();
			$j('.w24-height').find('select').val('-');
			$j('.w24-width').find('select').val('-');
			$j('.w24-heizkoerper-bottom-inner-product-box-text').show();
			$j('.w24-heizkoerper-bottom-inner-product-box-details').hide();
			$j('.w24-heizkoerper-bottom-inner-product-box-none').hide();
		}

		function w24_product_view_select(){
			$j('.w24-produkt-view-data-menue-inner').click(function(){
				if($j(this).is('.w24-deactivated')){
				}else{
					if($j(this).is('.w24-aktiv')){
						$j(this).css("background-color","#fff");
						w24_product_view_remove(this);
					}else{
						w24_product_view_remove(this);
						$j(this).css("background-color","#e4e2da");
						$j(this).addClass('w24-aktiv');
						if($j(this).is('.w24-produkt-view-toggle-1')){
							$j('.w24-produkt-view-data-zubehoer').show();
						}else if($j(this).is('.w24-produkt-view-toggle-2')){
							$j('.w24-produkt-view-data-beschreibung').show();
						}else if($j(this).is('.w24-produkt-view-toggle-3')){
							$j('.w24-produkt-view-data-tech-daten').show();
						}else if($j(this).is('.w24-produkt-view-toggle-4')){
							$j('.w24-produkt-view-data-downloads').show();
						}else if($j(this).is('.w24-produkt-view-toggle-5')){
							$j('.w24-produkt-view-data-rabattstaffel').show();
						}else if($j(this).is('.w24-produkt-view-toggle-6')){
							//$j('').show();
						}else if($j(this).is('.w24-produkt-view-toggle-7')){
							$j('.w24-produkt-view-data-verwandt').show();
						}else if($j(this).is('.w24-produkt-view-toggle-8')){
							//$j('').show();
						}
					}
				}
			});
		}

		function w24_product_view_remove(active){
			for( j=1 ; j<6 ; j++){
				k = j + 5;
				if($j(active).is('.w24-produkt-view-toggle-' + j)){
					for( i=1 ; i<6 ; i++){
						$j('.w24-produkt-view-toggle-' + i).removeClass('w24-aktiv');
						$j('.w24-produkt-view-toggle-' + i).css("background-color","#fff");
					}
					$j('.w24-produkt-view-data-1').hide();
				}else if($j(active).is('.w24-produkt-view-toggle-' + k)){
					for( i=6 ; i<11 ; i++){
						$j('.w24-produkt-view-toggle-' + i).removeClass('w24-aktiv');
						$j('.w24-produkt-view-toggle-' + i).css("background-color","#fff");
					}
					$j('.w24-produkt-view-data-2').hide();
				}
			}
		}

		function w24_product_view_mouseover(){
			$j('.w24-produkt-nachnahme-btn').mouseover(function(){
				$j(this).css("background-color","#0099d8");
				$j('.w24-produkt-possible').show();
				$j('.w24-produkt-impossible').hide();
			}).mouseout(function(){
				$j(this).css("background-color","#9f9d94");
				$j('.w24-produkt-possible').hide();
				$j('.w24-produkt-impossible').show();
			});

			$j('.w24-produkt-icon-1-toggle').mouseover(function(){
				$j('.w24-produkt-icon-1-mo').show();
				$j('.w24-produkt-icon-1-text').show();
				$j('.w24-produkt-icon-1').hide();
			}).mouseout(function(){
				$j('.w24-produkt-icon-1-mo').hide();
				$j('.w24-produkt-icon-1-text').hide();
				$j('.w24-produkt-icon-1').show();
			});

			$j('.w24-produkt-icon-2-toggle').mouseover(function(){
				$j('.w24-produkt-icon-2-mo').show();
				$j('.w24-produkt-icon-2-text').show();
				$j('.w24-produkt-icon-2').hide();
			}).mouseout(function(){
				$j('.w24-produkt-icon-2-mo').hide();
				$j('.w24-produkt-icon-2-text').hide();
				$j('.w24-produkt-icon-2').show();
			});

			$j('.w24-produkt-icon-3-toggle').mouseover(function(){
				$j('.w24-produkt-icon-3-mo').show();
				$j('.w24-produkt-icon-3-text').show();
				$j('.w24-produkt-icon-3').hide();
			}).mouseout(function(){
				$j('.w24-produkt-icon-3-mo').hide();
				$j('.w24-produkt-icon-3-text').hide();
				$j('.w24-produkt-icon-3').show();
			});

			$j('.w24-produkt-icon-4-toggle').mouseover(function(){
				$j('.w24-produkt-icon-4-mo').show();
				$j('.w24-produkt-icon-4-text').show();
				$j('.w24-produkt-icon-4').hide();
			}).mouseout(function(){
				$j('.w24-produkt-icon-4-mo').hide();
				$j('.w24-produkt-icon-4-text').hide();
				$j('.w24-produkt-icon-4').show();
			});
		}

	});

/*END*/
});

function w24_loading()
{
	var $ = jQuery;
	var self = this;
	var loader = $('<div class="w24-loading"><div class="w24-loading-inner"></div></div>');
	
	this.start = function()
	{
		//console.log("start");
		loader.hide();
		$("body").append(loader);
		loader.fadeIn();
	}
	
	this.end = function()
	{
		//console.log("end");
		loader.remove();
	}
};

