﻿/* Author: SW, schalk&friends - Agentur fÃ¼r neue Medien GmbH, 2011-02-09 */

/* Declare a namespace for the site */
var Site = window.Site || {};

/* Create a closure to maintain scope of the '$'
   and remain compatible with other frameworks.  */
(function($) {
	
	//same as $(document).ready();
	$(function() {	
		
		/*****************
		 *  KONTAKTKARTE *
		 *****************/
		
		$('div.sidebar').children('a').each(function(i,e) {
			if($(e).attr('data-country') == 'Deutschland') {
				$(this).attr('style','display:block;');
			}
		});
		
		$('select#sidebar_country').change(function(){
			var country = $(this).val();

			$('div.sidebar').children('a').each(function(i,e) {
				$(e).hide();
				if($(e).attr('data-country') == country) {
					$(this).attr('style','display:block;');
				}
			});
		});
		
		/****************
		 *  STARTSEITE  *
		 ****************/
		
		/* Eventliste als jQuery-Tools-Scrollable darstellen */
		
		if($("#events .scrollable ul").length>0) {
			$("#events .scrollable").scrollable({ circular: true });
		}
		
		if($(".partnerSlider .scrollable ul").length>0) {
			
	
			$(".partnerSlider .scrollable").scrollable({ circular: true });
		}
		
		/* News-Tabs als jQuery-Tools-Tabs - Automatisches durchsliden*/
		if($("#news ul.tabs").length) {
			$("#news ul.tabs").tabs("div.panes > div", {
				// enable "cross-fading" effect
				effect: 'fade',
				fadeOutSpeed: 2000,

				// start from the beginning after the last tab
				rotate: true

			// use the slideshow plugin. It accepts its own configuration
			}).slideshow({interval: 8000});
			$("#news ul.tabs").data("slideshow").play();
		}
		
		if($(".productOverview ul.tabs").length) {
			/*$(".productOverview ul.tabs").tabs("div.panes > ul", {
				// enable "cross-fading" effect
				effect: 'slide',
				initialIndex: null
			});
			
			$(".productOverview ul.tabs li a").click(function(){
				$(".productOverview ul.tabs li").removeClass("active");
				$(this).parent().addClass("active");
				$(this).parent().parent().parent().parent().siblings().children(".navProductOverview").children(".panes").children().hide();// Alle geÃ¶ffneten Tabs sonstiger productOverviews anderer Kategorien schlieÃŸen 
				$(this).parent().parent().parent().siblings().children(".panes").children().hide(); // Alle geÃ¶ffneten Tabs sonstiger productOverviews in dieser Kategorie schlieÃŸen
			});
			*/
			
			$(".productOverview ul.tabs li a").click(function(){
				id = $(this).parent().attr("id");
				
				if($(this).parent().hasClass("active")) {
					$(".navProductOverview .tabs li").removeClass("active"); // Alle Tabs deaktivieren
					$(".navProductOverview .panes ul").hide(); // alle Contents ausblenden
					
					$("#content_" + id).show(); 
					$("#content_" + id).slideUp( "slow"); // Aktuellen Content ausblenden
					$(this).parent().removeClass("active"); // Aktuelles Tab deaktivieren
				} else {
					$(".navProductOverview .tabs li").removeClass("active"); // Alle Tabs deaktivieren
					$(".navProductOverview .panes ul").hide(); // alle Contents ausblenden
					$("#content_" + id).slideDown( "slow"); // Aktuellen Content anzeigen
					$(this).parent().addClass("active"); // Aktuelles Tab aktivieren
				}
			});
			
	
			
		}
		
		if($("#gallery ul.tabs").length) {
			$("#gallery ul.tabs").tabs("div.panes > img", {

				// enable "cross-fading" effect
				effect: 'fade',
				fadeOutSpeed: 2000
			});
		}
		
		if($("#events .scrollable").length) {
			$("#events .scrollable").scrollable({ circular: true });
		}	
		
		/* Letztes Event in einer Zeile mit class="last" versehen, wg. rechtem Margin */
		if($(".eventWrapper ul li").length) {
			$(".eventWrapper ul li:last-child").addClass('last');
		}
		
		$('#slider').innerfade({
			speed: 1500,
			timeout: 5000,
			type: 'sequence',
			containerheight: '120px'
		});

		$(".navProductOverview ul.tabs li").each(function(index){ /* Text mittig in den Tabs ausrichten */
			$(this).children("a").css("margin-top", (50 - $(this).children("a").height())/2);
			$(this).children("a").css("margin-bottom", (50 - $(this).children("a").height())/2);
		});
		
		$("#sword_top").click(function(){
			if($(this).val() == 'Nach Produkt, Infos usw.' || $(this).val() == 'Search for product, info etc.') {
				$(this).val('');
			}
		});
		

		if($("#faq-1").length) {
			$("#faq-1").hide();
			$("#faq-1 .faqInnerWrapper").height('420px');
		}	
		
		var mylang=0;
		if($('#navLanguages .current a').html()=="EN"){
			var mylang=1;

		}
		
			/*
			if($("#uid33")){
				var uidobj=$("#uid33");
			}
		*/
			if($("#uid1")){
				var uidobj=$("#uid1");
			}
		
	
		
		function loadData(uidobj){
			$.ajax({
				url: "index.php",               // Achtung mit RealURL!
				type: "GET",                    // Daten per GET verschicken
				data: {
					eID: "addressgroups",       // die erstellte eID
					input: uidobj.val(),
					lang: mylang
				},
				dataType: "json",  
				context: document.body,
				success: function(response){
					$('.ansprechpartner p').html(response[0]);
					if(mylang == 1) {
						$('input[name$="tx_powermail_pi1[uid77]"]').val(response[1]);
						$('input[name$="tx_powermail_pi1[uid91]"]').val(response[2]);
			    	} else {
			    		$('input[name$="tx_powermail_pi1[uid76]"]').val(response[1]);
			    		$('input[name$="tx_powermail_pi1[uid90]"]').val(response[2]);
			    	}
			  }
			});
		}
		
		
		if(uidobj){
			loadData(uidobj);
			uidobj.change(function(){
				loadData(uidobj);
			});
		}
		
	});

	$(window).bind("load", function() {

	});
	
})(jQuery);


