jQuery.noConflict();

function libAGENTURNET() {
	jQuery('#agentur_net').hover(
		function() {
			jQuery(this).find('ul li ul').show('slow');
		},
		function() {
			jQuery(this).find('ul li ul').hide('slow');
		}
	);
	
	jQuery('#agentur_net').click(
		function() {
			//alert(jQuery(this).find('a').attr('href'));
			//window.parent.location = jQuery(this).find('a').attr('href');
			window.open(jQuery(this).find('a').attr('href'));
		}
	);
}

function mediarotate(max, act, zindex) {
	// Oberstes Bild ausblenden
	jQuery("#teaser div.mediaimage").eq(act).fadeOut("slow");
	
	// Bild unten wieder einfügen
	setTimeout(function(){
		jQuery("#teaser div.mediaimage").eq(act).css("z-index",zindex);
	
		jQuery("#teaser div.mediaimage").eq(act).fadeIn("slow");
	}, 1000);
	
	// Rotation erneut starten
	setTimeout(function(){
		if (act == max) {
			// z-index überprüfen
			if (zindex <= 10) {
				// Alle vorhandenen Elemente im z-index um 1000 erhöhen
				for (i=0; i<max; i++) {
					zindex = 1000 - i;
					jQuery("#teaser div.mediaimage").eq(i).css("z-index",zindex);
				}
			}
			act = -1;
		}
		mediarotate(max, act + 1, zindex - 1);
	}, 5000);
}

function libMEDIA() {

	if(jQuery("#loopedSlider").length <= 0) {
		// Alle Media Bilder mit z-index versehen und anzeigen sowie den Rotationswinkel festlegen
		j = 0;
		for (i=0; i<jQuery("#teaser div.mediaimage").length; i++) {
			zindex = 1000 - i;
			
			jQuery("#teaser div.mediaimage").eq(i).show();
			jQuery("#teaser div.mediaimage").eq(i).css("z-index",zindex);
		}
		
		// Erste Rotation nach 5 Sekunden starten, wenn mehr als ein Bild
		if (i > 1) {
			setTimeout(function(){
				mediarotate(jQuery("#teaser div.mediaimage").length - 1, 0, zindex - 1);
			}, 5000);
		}
	}else{ //Mediaanimation for Receiver-Site
		var i=1;
		jQuery(".mediaimage").each(function(){
			jQuery(this).attr('id', "slide_"+i);
			jQuery("<li><a id='"+i+"' class='imageLink' href='#'>Image"+i+"</a></li>").appendTo("#slide-nav-bottom >ul");
			i++;
		});
		
		
		
		
		/*jQuery(".imageLink").click(
        function() {
			alert("click");
            //jQuery(this).addClass("active");
			alert(jQuery(this).attr("id"));
			return false;
		});*/
		
		jQuery.fn.loopedSlider.defaults.addPagination = true;
		jQuery('#loopedSlider').loopedSlider({
			container: ".slideContainer",
			slidespeed: 800,
			fadespeed: 200,
			autoStart: 8500,
			restart: 5000

		});

		jQuery('#loopedSlider').mouseover(function(){
			jQuery("#slide-nav > .previous").css('display','inline');
			jQuery("#slide-nav > .next").css('display','inline');
		});
		
		jQuery('#loopedSlider').mouseout(function(){
			jQuery("#slide-nav > .previous").css('display','none');
			jQuery("#slide-nav > .next").css('display','none');
		
		});
	}
}

function libTOOLBAR() {
    jQuery('#footer-teaser .toolbar_item').hoverIntent(
        function() {
            jQuery('#footer-teaser').height(250);
            jQuery(this).animate(
                {
                    height: '250'
                },
                {
                    duration: 200, 
                    specialEasing: {
                        height: 'linear'
                    },
                    complete: function() {
                    // Animation complete.
                    }
                }
            );
            
            jQuery(this).find('img').css('height','100%')
            jQuery(this).find('img').css('width','100%')
        },
        function() {
            jQuery('#footer-teaser').height(65);
            jQuery(this).animate(
                {
                    height: '65'
                },
                {
                    duration: 200, 
                    specialEasing: {
                        height: 'linear'
                    },
                    complete: function() {
                    // Animation complete.
                    }
                }
            );
            jQuery(this).find('.teaser_header img').css('height','80%')
            jQuery(this).find('.teaser_header img').css('width','80%')
            jQuery(this).find('.teaser_image img').css('height','70%')
            jQuery(this).find('.teaser_image img').css('width','70%')
        } 
    );
}

function libSUBMENU_SLIDE() {
    
	
	
	jQuery("#sub-navigation>ul.lev1>li>ul.lev2").hide();
	
	/*jQuery("#sub-navigation>ul.lev1>li>a.ifsub").mouseover(function() {
		if (jQuery(this).next('ul.lev2').is(":hidden")) {
            jQuery(this).next('ul.lev2').slideDown("slow");
        }
	});*/
	
	if(jQuery("#sub-navigation>ul.lev1>li>a.curifsub").next('ul.lev2').is(":hidden")){
		jQuery("#sub-navigation>ul.lev1>li>a.curifsub").next('ul.lev2').slideDown("slow");
	}
	if(jQuery("#sub-navigation>ul.lev1>li>a.actifsub").next('ul.lev2').is(":hidden")){
		jQuery("#sub-navigation>ul.lev1>li>a.actifsub").next('ul.lev2').slideDown("slow");
	}
	
	
	
   /* jQuery("#sub-navigation>ul.lev1>li>a.ifsub").click(function () {
        if (jQuery(this).next('ul.lev2').is(":hidden")) {
            jQuery(this).next('ul.lev2').slideDown("slow");
        } else {
            if(!jQuery(this).hasClass('curifsub')) {
                jQuery(this).next('ul.lev2').slideUp("slow");
            }
        }
 
    });*/
    if(jQuery('div.produkte').length <= 0) {
		jQuery("#sub-navigation>ul.lev1>li>ul.lev2>li>ul.lev3").hide();
		
		jQuery("#sub-navigation>ul.lev1>li>ul.lev2>li>a.curifsub").next('ul.lev3').slideDown("slow");
		jQuery("#sub-navigation>ul.lev1>li>ul.lev2>li>a.actifsub").next('ul.lev3').slideDown("slow");
		
        jQuery("#sub-navigation>ul.lev1>li>ul.lev2>li>a.ifsub").click(function () {
            if (jQuery(this).next('ul.lev3').is(":hidden")) {
                jQuery(this).next('ul.lev3').slideDown("slow");
            } else {
                if(!jQuery(this).hasClass('curifsub')) {
                    jQuery(this).next('ul.lev3').hide();
                } 
            }
          
        });
    }
	
    /*jQuery("#sub-navigation>ul.lev1>li>a.ifsub").hover(
        function() {
            var cssObj = {
                "background": "url('fileadmin/img/sub-ul_li_a_active.png') no-repeat 12px center #adbac0"
            }

            jQuery(this).css(cssObj);
        },
        function() {
            var cssObj = {
                "background-color" : "#adbac0",
                "background": "url('fileadmin/img/sub-ul_li_a.png') no-repeat 12px center transparent"
            }

            jQuery(this).css(cssObj);
        }
    
    );*/
    
}

function libStandorte() {

    if(jQuery('map#ansprechpartner').size() > 0) {
		
		jQuery('#content .content-element').hide();
	    jQuery('#content .content-element:first').show();
	    jQuery('map#ansprechpartner').parent().parent().show();
			
		
		
		if(jQuery('h1').text() == "Salzburg"){	
			showStandortbox("Salzburg");
			jQuery('#content #content-element-171').show();		
		}else if(jQuery('h1').text() == "Wien"){
			showStandortbox("Wien");
			jQuery('#content #content-element-173').show();
		}else if(jQuery('h1').text() == "Gratkorn"){
			showStandortbox("Gratkorn");
			jQuery('#content #content-element-174').show();
		}else if(jQuery('h1').text() == "VÃ¶ls"){
			showStandortbox("VÃ¶ls");
			jQuery('#content #content-element-172').show();
		}
        
        
        jQuery('map#ansprechpartner area').click(function(e) {
			
            var ansprechpartner = jQuery(this).attr('title');
            
            jQuery('#content .content-element h2').each(function(index) {
                if(jQuery(this).text() == ansprechpartner) {
                    jQuery('#content .content-element').hide();
                    jQuery('map#ansprechpartner').parent().parent().show();
                    jQuery(this).parents('.content-element').addClass('ansprechpartner');
                    posTop = e.pageY - jQuery(this).parents('.content-element').height() - jQuery(this).parents('#content').offsetTop - 35;
                    posLeft = e.pageX - jQuery(this).parents('.content-element').width() - jQuery(this).offsetLeft - 35;
                    
                    posTop = 160;
                    
                    
                   /*  if(posTop < 220) { posTop = 220; } 
                    if(posLeft < 730) { posLeft = 730; } 
                    if(posLeft > 920) { posLeft = 920; } */
                    jQuery(this).parents('.content-element').css('top','160px');
                    //jQuery(this).parents('.content-element').css('left',posLeft+'px');
                    
                    jQuery(this).parents('.content-element').show();
                    jQuery('#content .content-element:first').show();
                    jQuery(this).parents('.content-element').click(function() {
                        jQuery(this).hide();
                    });
					
					if(jQuery('h1').text() == "Salzburg"){	
						jQuery('#content #content-element-171').show();		
					}else if(jQuery('h1').text() == "Wien"){
						jQuery('#content #content-element-173').show();
					}else if(jQuery('h1').text() == "Gratkorn"){
						jQuery('#content #content-element-174').show();
					}else if(jQuery('h1').text() == "VÃ¶ls"){
						jQuery('#content #content-element-172').show();
					}
                }
            });
            
            //return false;
        });
    }
}

function showStandortbox(boxname){
	jQuery('#content .content-element h2').each(function(index) {
                if(jQuery(this).text() == boxname) {
                    jQuery('#content .content-element').hide();
                    jQuery('map#ansprechpartner').parent().parent().show();
                    jQuery(this).parents('.content-element').addClass('ansprechpartner');
                    
                    posTop = 160;
                 
                    jQuery(this).parents('.content-element').css('top','160px');
                    
                    
                    jQuery(this).parents('.content-element').show();
                    jQuery('#content .content-element:first').show();
                    jQuery(this).parents('.content-element').click(function() {
                        jQuery(this).hide();
                    });
                }
            });
}

function libReceiverSingleView(){
	 if(jQuery('.tt_news_single_product').size() > 0) {
		//jQuery('.csc-textpic-imagewrap > .csc-textpic-imagerow:first-child').css({backgroundColor: '#ffe', borderLeft: '5px solid #ccc'});
	 }
}

function libReceiverListView(){
	 if(jQuery('.tt_news_list_product').size() > 0) {
		jQuery(".category").each(function(){
			
			var funktionen = jQuery(this).text();
			var funktionenNEU = funktionen.replace(/, Ausgewaehlte Produkte/g, " ");
			funktionenNEU = funktionenNEU.replace(/Funktionen:/g, "<strong>Funktionen: </strong> ");
			jQuery(this).html(funktionenNEU);
		//alert(funktionenNEU);
		});
		
	 }
}

function locator_display() {
    jQuery('.tx-locator-pi1 li.lb2').each(
        function() {
            if(!jQuery(this).text()) {
				
                jQuery(this).css('display','none');
                jQuery(this).prev().css('display','none');
            }
        }
    );
	
	jQuery('.tx-locator-pi1 div.c2').each( //Categories
        function() {
				
				if(jQuery.trim(jQuery(this).text()) == '3' || jQuery.trim(jQuery(this).text()) == '3,2'){ //H - Haendler
					jQuery(this).html('<img class="h_icon" src="fileadmin/img/locator/pointerWhite_H.gif" width="35" height="35" title="Fachh&auml;ndler mit einer gro&szlig;en Auswahl an KATHREIN Produkten sowie Beratungs- und Serviceangeboten" alt="Fachh&auml;ndler mit einer gro&szlig;en Auswahl an KATHREIN Produkten sowie Beratungs- und Serviceangeboten" />');
				}else if (jQuery.trim(jQuery(this).text()) == '4' || jQuery.trim(jQuery(this).text()) == '4,2'){ //I-Haendler
					jQuery(this).html('<img class="i_icon" src="fileadmin/img/locator/pointerWhite_I.gif" width="35" height="35" title="Fachhandel und Installationsservice mit einer gro&szlig;en Auswahl an KATHREIN Produkten."  alt="Fachhandel und Installationsservice mit einer gro&szlig;en Auswahl an KATHREIN Produkten." />');
				}else if(jQuery.trim(jQuery(this).text()) == '5' || jQuery.trim(jQuery(this).text()) == '5,2'){ //I+ Haendler
					jQuery(this).html('<img class="iplus_icon" src="fileadmin/img/locator/pointerWhite_Iplus.gif" width="35" height="35" title="Fachhandel und Installationsservice mit einer gro&szlig;en Auswahl an KATHREIN Produkten. Planung sowie Wartung von Gemeinschaftsantennenanlagen." alt="Fachhandel und Installationsservice mit einer gro&szlig;en Auswahl an KATHREIN Produkten. Planung sowie Wartung von Gemeinschaftsantennenanlagen." />');
				}else if(jQuery.trim(jQuery(this).text()) == '2'){
					jQuery(this).css('display','none');
				}
                
               
        }
    );
	
	 if(jQuery('#route').size() > 0) {
		jQuery('.contenttable-0').css('display','none');
	 }
}


jQuery(document).ready(function() {
	libAGENTURNET();
	libMEDIA();
    libTOOLBAR();
	   libStandorte();
  // libSUBMENU_SLIDE();

   libReceiverSingleView();
   libReceiverListView();
   locator_display();
    jQuery("tr:nth-child(odd)").addClass("odd");
    jQuery('.product_overview a').hover(
        function() {
            jQuery(this).find("span.product_overview_textlink img").css("top","-20px");
        },
        function() {
            jQuery(this).find("span.product_overview_textlink img").css("top","0px");
        }
    );
});
