//Allowing Get Vars
HTTP_GET_VARS=new Array();
strGET=document.location.search.substr(1,document.location.search.length);
if(strGET!='')
{
	gArr=strGET.split('&');
	for(i=0;i<gArr.length;++i)
	{
		v='';vArr=gArr[i].split('=');
		if(vArr.length>1){v=vArr[1];}
		HTTP_GET_VARS[unescape(vArr[0])]=unescape(v);
	}
}

function GET(v)
{
	if(!HTTP_GET_VARS[v]){return 'undefined';}
	return HTTP_GET_VARS[v];
}

// HASH CHANGE FUNCTION
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);

if(jQuery){
	


	function dropTyp(input, img, that){
		$(that).attr('src',img);
		$('#'+input).hide();
	}
	function closeDrop(input,img,that){
		$(that).attr('src',img);
		$('#'+input).show();
	}
	
	/*$(function(){
		$('.produkt_box, .provider_list li').live('click',function(){
			self.location = $(this).attr('href');
		});
	});*/
	
	$(document).ready(function(){
		
		
		function filterPath(string) {
			return string
				.replace(/^\//,'')
				.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
				.replace(/\/$/,'');
			}
			var locationPath = filterPath(location.pathname);
			var scrollElem = scrollableElement('html', 'body');
		
			$('a[href^=#]').each(function() {
				var thisPath = filterPath(this.pathname) || locationPath;
				if (  locationPath == thisPath
				&& (location.hostname == this.hostname || !this.hostname)
				&& this.hash.replace(/#/,'') ) {
					var $target = $(this.hash), target = this.hash;
					if (target && $target.length > 0) {
						var targetOffset = $target.offset().top;
						$(this).click(function(event) {
							event.preventDefault();
							$(scrollElem).animate({scrollTop: targetOffset}, 600, function() {
								location.hash = target;
							});
						});
					}
				}
			});
		
			// use the first element that is "scrollable"
			function scrollableElement(els) {
				for (var i = 0, argLength = arguments.length; i <argLength; i++) {
					var el = arguments[i],
							$scrollElement = $(el);
					if ($scrollElement.scrollTop()> 0) {
						return el;
					} else {
						$scrollElement.scrollTop(1);
						var isScrollable = $scrollElement.scrollTop()> 0;
						$scrollElement.scrollTop(0);
						if (isScrollable) {
							return el;
						}
					}
				}
				return [];
			}

		
		
		
		if($('[name=ChangeProdukt]').index() != -1){
			$('[name=ChangeProdukt]').html($.ajax({
				url: 'ajax/Produkt/ChangeProdukt.php',
				type : 'GET',
				async : false,
				data: 'products_id='+$('#Produkt').attr('pid')+'&master_id='+$('#Produkt').attr('mid')+'&categories_id='+$('[name=ChangeProdukt]').attr('cid')
			}).responseText);
			
			$('[name=ChangeProdukt]').live('change', function(){
				window.location = $(':selected', this).val();
				//$('form[name=FormChangeProduct]').attr('action',$(this).val()).submit();
			});
		}
		
		if($('#Produkt').attr('pid') > 0 && $('#Produkt').attr('mid') > 0){
			$('.Varianten').html($.ajax({
				url: 'ajax/Produkt/Varianten.php',
				type : 'GET',
				async : false,
				data: 'products_id='+$('#Produkt').attr('pid')+'&master_id='+$('#Produkt').attr('mid')
			}).responseText);
		}
		
		var VarianteZaehler = 0;
		
		$('.Varianten li.first').live('click', function(){
			VarianteZaehler--;
			$('.Varianten').html($.ajax({
				url: 'ajax/Produkt/Varianten.php',
				type : 'GET',
				async : false,
				data: 'products_id='+$('#Produkt').attr('pid')+'&master_id='+$('#Produkt').attr('mid')+'&action=increase&zaehler='+VarianteZaehler
			}).responseText);
		});
		$('.Varianten li.last').live('click', function(){
			VarianteZaehler++;
			$('.Varianten').html($.ajax({
				url: 'ajax/Produkt/Varianten.php',
				type : 'GET',
				async : false,
				data: 'products_id='+$('#Produkt').attr('pid')+'&master_id='+$('#Produkt').attr('mid')+'&action=decrease&zaehler='+VarianteZaehler
			}).responseText);
		});
						
		$('input[type=text], select, input[type=password]').live('focus', function(){
			$(this).addClass('focus');	
			$(this).parent().find('div.leftwrap').addClass('focus');
			if($(this).attr('default') == $(this).val()){
				$(this).val('');
			}
		});
		$('input[type=text], select, input[type=password]').live('blur', function(){
			$(this).removeClass('focus');	
			$(this).parent().find('div.leftwrap').removeClass('focus');
			if($(this).attr('default') == $(this).val() || $(this).val() == ''){
				$(this).val($(this).attr('default'));
			}
		});

		
		
		function runSlideShow(){
			var IndexId = $('.checkout_trustbar ul.slideshow li').index('.checkout_trustbar ul.slideshow li:visible');
			if(typeof $('.checkout_trustbar ul.slideshow li')[IndexId+1] == 'object'){
				$('.checkout_trustbar ul.slideshow li:visible').hide();
				$('.checkout_trustbar ul.slideshow li').eq(IndexId+1).show();
			}else{
				$('.checkout_trustbar ul.slideshow li:visible').hide();
				$('.checkout_trustbar ul.slideshow li:first-child').show();
			}
			setTimeout(runSlideShow,3000);			
		}
		
		if($('.checkout_trustbar ul.slideshow').index() != -1){
			$('.checkout_trustbar ul.slideshow li:first-child').show();
			setTimeout(runSlideShow,3000);
		}
		
		
		if((typeof $().jshowoff == 'function')){
			$('#slidingFeatures').jshowoff({
					speed:6000, controls: false, effect: 'slideLeft', links: false, hoverPause: false
			});
		}
		
		$('.jsTglRevStars img').live('mouseover', function(){
			var index = $('.jsTglRevStars img').index(this);
			$('.jsTglRevStars [name=reviews_stars]').val(index+1);
			var xc = 0;
			var path = $(this).attr('src').replace(/star_on.gif|star_off.gif/g, '');
			while(xc <= 5){
				if(xc <= index){
					$($('.jsTglRevStars img')[xc]).attr('src', path+'star_on.gif');
				}else{
					$($('.jsTglRevStars img')[xc]).attr('src', path+'star_off.gif');
				}
				xc++;
			}
		});
		
		$('#Produkt .LayerLinks .Vergleichen').live('click', function(){
			var pid = $('#Produkt').attr('pid');
			$.ajax({
				data: 'products_id='+pid,
				dataType: 'html',
				type: 'GET',
				url: 'ajax/Produkt/Vergleich.php',
				success: function(data){
					$(data).dialog({
						width: 600,
						height: 300,
						modal:true,
						buttons: {'Schließen' : function(){ $(this).remove(); }}
					});
				}
			});
		});
		$('#Produkt .LayerLinks .Beschreibung').live('click', function(){
			var pid = $('#Produkt').attr('pid');
			$.ajax({
				data: 'products_id='+pid,
				dataType: 'html',
				type: 'GET',
				url: 'ajax/Produkt/Beschreibung.php',
				success: function(data){
					$(data).dialog({
						width: 600,
						height: 500,
						modal:true,
						buttons: {'Schließen' : function(){ $(this).remove(); }}
					});
				}
			});
		});
		$('#Produkt .LayerLinks .Bewertung').live('click', function(){
			var pid = $('#Produkt').attr('pid');
			var mid = $('#Produkt').attr('mid');
			$.ajax({
				data: 'products_id='+pid+'&master_id='+mid,
				dataType: 'html',
				type: 'GET',
				url: 'ajax/Produkt/Bewertungen.php',
				success: function(data){
					$(data).dialog({
						width: 600,
						height: 500,
						modal:true,
						buttons: {
							'Bewertung abschicken' : function(){ 
							var $that = $(this);
								$.ajax({
									data: $('input, textarea',this),
									dataType: 'html',
									type: 'POST',
									url: 'ajax/Produkt/Bewertungen.php',
									success: function(data){
										$that.html(data);
										$that.remove();
									}
								});
							 },
							'Schließen' : function(){ $(this).remove(); }
						}
					});
				}
			});
		});
//		$('#Produkt .LayerLinks .Video').live('click', function(){
//			var pid = $('#Produkt').attr('pid');
//			$.ajax({
//				data: 'products_id='+pid,
//				dataType: 'html',
//				type: 'GET',
//				url: 'ajax/Produkt/Videos.php',
//				success: function(data){
//					$(data).dialog({
//						width: 600,
//						height: 500,
//						modal:true,
//						buttons: {'Schließen' : function(){ $(this).remove(); }}
//					});
//				}
//			});
//		});
		$('#Produkt .Datenblatt').live('click', function(){
			var pid = $('#Produkt').attr('pid');
			$.ajax({
				data: 'products_id='+pid,
				dataType: 'html',
				type: 'GET',
				url: 'ajax/Produkt/Datenblatt.php',
				success: function(data){
					$(data).dialog({
						width: 600,
						height: 500,
						modal:true,
						buttons: {'Schließen' : function(){ $(this).remove(); }}
					});
				}
			});
		});
		
		$('.PreisAlarm').live('click', function(){
			var pid = $(this).attr('pid');
			var tid = $(this).attr('tid');
			$.ajax({
				data: 'products_id='+pid+'&products_options_values_id='+tid,
				dataType: 'html',
				type: 'GET',
				url: 'ajax/Produkt/PreisAlarm.php',
				success: function(data){
					$(data).dialog({
						width: 600,
						height: 250,
						modal:true,
						buttons: {
							'Eintragen' : function(){ 
								var $that = $(this);
								$.ajax({
									data: $('input',this),
									dataType: 'html',
									type: 'POST',
									url: 'ajax/Produkt/PreisAlarm.php',
									success: function(data){
										$that.html(data);
										//$that.remove();
									}
								});
							 },
							'Schließen' : function(){ $(this).remove(); }
						}
					});
				}
			});
		});
		
		
		
		
	$('.versandkosten').live('click', function(){
			$(
				$.ajax({
				async: false,
				url: 'inc/versandkosten.php'
			}).responseText
			).dialog({
				width: 500,
				height: 500,
				modal:true,
				buttons: {
					'abbrechen' : function(){ $(this).remove(); }
				}
			});
		});
		
		
		// XSELL
		
		$('.crossselling li').live('click',function(e){
			if($(e.originalTarget).hasClass('versandkosten')) return true;
			var pid = $(this).attr('id');
			$.ajax({
				data: 'products_id='+pid,
				dataType: 'html',
				type: 'POST',
				async: false,
				url: 'ajax/products_layer.php',
				success: function(data){
					var $diag = $(data).dialog({
						width: 500,
						height: 500,
						modal:true,
						buttons: {
							'In den Warenkorb' : function(){
								var $that = $(this);
								$.ajax({
									data: 'products_id='+pid,
									dataType: 'json',
									type: 'POST',
									async: false,
									url: 'product_info.php?products_id='+pid+'&action=add_product',
									success: function(){
									}
								});
								var count = parseInt($('#header_cart_icon .cart_counter').html());
								$('#header_cart_icon .cart_counter').html(count+1);
								$that.html('Erfolgreich in den Warenkorb gelegt!');
								$that.dialog({buttons:{'Weiter' : function(){ $(this).remove(); }}});
							},
							'abbrechen' : function(){ $(this).remove(); }
						}
					});

					$('.warenkorb',$diag).click(function(){
							$.ajax({
								data: 'products_id='+pid,
								dataType: 'json',
								type: 'POST',
								async: false,
								url: 'product_info.php?products_id='+pid+'&action=add_product',
								success: function(){
								}
							});
							var count = parseInt($('#header_cart_icon .cart_counter').html());
							$('#header_cart_icon .cart_counter').html(count+1);
							$diag.html('Erfolgreich in den Warenkorb gelegt!');
							$diag.dialog({ buttons:{'abbrechen' : function(){ $(this).remove(); }}});
					});
				}
			});
		});	
		
		
		// XSELL ENDE
		
		// WARENKORB
		
		$('.shoppingcart_info, .shoppingcart_info img').live('click',function(){
			var pid = $(this).attr('pid');
			$.ajax({
				data: 'products_id='+pid,
				dataType: 'html',
				type: 'POST',
				async: false,
				url: 'ajax/products_layer.php',
				success: function(data){
					var $diag = $(data).dialog({
						width: 500,
						height: 500,
						modal:true,
						buttons: {
							'abbrechen' : function(){ $(this).remove(); }
						}
					});
				}
			});
		});

		
		// ENDE
		
		
		
		
	var $tabs = $('#sTopSellers').tabs();

	$('.TopSellersPrev').live('click',function(){
		refreshIndex(this,'-');
	});
	$('.TopSellersNext').live('click',function(){
		refreshIndex(this,'+');
	});
	var refreshIndex = function(that, op){
		var index = $('li.ui-state-active',$tabs).index();
		var limit = parseInt($('#sTopSellers').attr('class').replace('limit',''));
		if(op == '-'){
			if((jspArr[index].limit - limit) < 0){
				jspArr[index].limit = 0;
			}else{
				jspArr[index].limit -= limit;
			}
		}
		if(op == '+'){
			jspArr[index].limit += limit;
		}
		var UseTid = null;
		if(typeof jspArr[index].TarifID == 'string'){
			UseTid = jspArr[index].TarifID;
		}
		var getObj = {
				'id' : jspArr[index].id,
				'TarifID' : UseTid,
				'l' : jspArr[index].limit+','+limit
			};
	
		$(that).closest('.ui-tabs-panel').html($.ajax({
			url: 'ajax/LoadTopSellers.php',
			type : 'GET',
			async:false,
			data: getObj
 		}).responseText);
		//$tabs.tabs({ load: index });
	}	
		
		$('.table_tarife_list tbody tr').bind({
			mouseover: function(){
				$('td:last img',this).attr('src','img/design/buttons/button-details-small.jpg');
			},
			mouseout: function(){
				$('td:last img',this).attr('src','img/design/buttons/button-details-small-over.jpg');
			}
		});
		
		
		if(typeof jQuery.ui == 'object'){
			
			$('.btnTarifDetails').live('click', function(){
				var TarifId = $(this).attr('TarifId')
				$.ajax({
					data: 'TarifId='+TarifId,
					dataType: 'html',
					type: 'POST',
					async: true,
					url: 'ajax/TarifDetails.php',
					success: function(data){
						$(data).dialog({
							modal: true,
							width: 'auto',
							buttons: {'Schließen' : function(){ $(this).remove(); }}
						});
					}
				});
			});
			$('.btnContractOptionDetails').live('click', function(){
				var OptionsId = $(this).attr('OptionsId')
				$.ajax({
					data: 'OptionsId='+OptionsId,
					dataType: 'html',
					type: 'POST',
					async: true,
					url: 'ajax/ContractOptionDetails.php',
					success: function(data){
						$(data).dialog({
							modal: true,
							width: 'auto',
							buttons: {'Schließen' : function(){ $(this).remove(); }}
						});
					}
				});
			});
			$('.btnGrundTarifOptionDetails').live('click', function(){
				var OptionsId = $(this).attr('OptionsId')
				$.ajax({
					data: 'OptionsId='+OptionsId,
					dataType: 'html',
					type: 'POST',
					async: true,
					url: 'ajax/GrundTarifOptionDetails.php',
					success: function(data){
						$(data).dialog({
							modal: true,
							width: 'auto',
							buttons: {'Schließen' : function(){ $(this).remove(); }}
						});
					}
				});
			});
			
			
			$("#tabs").tabs();
			$('.modinfo').click(function(evt){
				var iHeight = $(this).attr('height') ? $(this).attr('height') : 'auto';
				var iWidth = $(this).attr('width') ? $(this).attr('width') : 'auto';
				$('<div>'+$(this).attr('title')+'</div>').dialog({
					title: $('img',this).attr('title'),
					modal: true,
					height: iHeight,
					width: iWidth
					/*position: [evt.target.x-20, evt.target.y-20]*/
				});
			});
			// ModInfo as Ajax
			$('.ajaxinfo').click(function(evt){
				var that = this;
				var TarifID = parseInt($(that).attr('id').replace('tid_',''));
				if(TarifID > 0){
					$.ajax({
						data: 'TarifID='+TarifID,
						dataType: 'html',
						type: 'POST',
						async: true,
						url: 'ajax/ajaxinfo.php',
						success: function(data){
							$('<div>'+data+'</div>').dialog({
								title: $(that).attr('title'),
								modal: true,
								width: 'auto'
							});
						}
					});
				}
			});
			$(".tecdata").live('click',function () {
			 $(".data",$(this).parent()).toggle("slow");
			});  
			// ModInfo as Ajax Clock
			$('.ajaxinfo2').click(function(evt){
				var that = this;
				var Ids = $(that).attr('id').split(' ');
				var TarifID = parseInt(Ids[0].replace('tid_',''));
				var ProduktId = parseInt(Ids[1].replace('pid_',''));
				if(TarifID > 0 && ProduktId > 0){
					$.ajax({
						data: 'TarifID='+TarifID+'&ProduktId='+ProduktId,
						dataType: 'html',
						type: 'POST',
						async: true,
						url: 'ajax/ajaxinfo2.php',
						success: function(data){
							$('<div>'+data+'</div>').dialog({
								title: $(that).attr('title'),
								modal: true,
								width: 'auto'
							});
						}
					});
				}
			});
			
		}
		
		$("button.tecdata").click(function () {
			$('#tecdata').toggle("slow");
		}); 
		
		
		
		/*$('#kblz').keyup(function(event){
			jQuery.ajax({
				data: 'blz='+$('#kblz').val(),
				dataType: 'json',
				type: 'POST',
				url: 'ajax/getblz.php',
				success: function(d){
					$('#kbank').val(d);
				}
			});
		});*/
					
		
					
		
		if ($("input[name='rufnr_portierung']:checked").val() == '1'){
			$("#DIVportierung").show();
		}else if ($("input[name='rufnr_portierung']:checked").val() == '0'){
				$("#DIVportierung").hide();	
		}
		
		$("input[name='rufnr_portierung']").click(function()
		{
			if ($("input[name='rufnr_portierung']:checked").val() == '1')
			{
					$("#DIVportierung").show("slow");
			}
			else if ($("input[name='rufnr_portierung']:checked").val() == '0')
			{
					$("#DIVportierung").hide("slow");	
			}
		});
		if((typeof $().lightBox == 'function')){
			$('#gallery span').lightBox();
		}
		if((typeof $().msAccordion == 'function')){
			$("#accordionGiftLelo").msAccordion({defaultid:0, autodelay:6});
 			$("#accordionGiftLelo").show();
		}
		$('#provider_selector img, .dropselector').bind({
		mouseover	: function(){
			var alt = $(this).attr('alt');
			var src = $(this).attr('src');
			var cl = $(this).attr('class');
			$(this).attr('alt',src);
			$(this).attr('src',alt);
			$('#'+cl).show();
		},
		mouseout : function(){
			var alt = 	$(this).attr('alt');
			var src = $(this).attr('src');
			$(this).attr('alt',src);
			$(this).attr('src',alt);
			var cl = $(this).attr('class');
			$('#'+cl).hide();
		}
	});
		
		$("#partnerbanner").hover(function(){
			$("#partnerbannerhover").fadeOut(100);
			$("#partnerbannerhover").fadeIn(500);
		});	
		$("#partnerbanner").mouseleave(function(){
			$("#partnerbannerhover").fadeOut(100);
		});	
	});
	
}


