var checkSelectChange;
jQuery.noConflict();
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();




document.write('<style type="text/css">');
document.write('.noscript {display:none}');
if(jQuery.browser.mozilla) {
	if(navigator.platform.match(/Win/)) {
		document.write('label.checkbox {position:relative;top:-2px}');
		document.write('.pagination ul li a {height: 20px;}');
	}
	document.write('#empfehlung .new {top:29px}');
}
if(window.opera) {
	document.write('#folgeseite #tickets li.withStation { height: 254px !important; }');
}








document.write('</style>');






/*disableTextSelect by Chris Barr http://chris-barr.com/entry/disable_text_selection_with_jquery/ */
jQuery.extend(jQuery.fn.disableTextSelect = function() {
	return this.each(function(){
		if(jQuery.browser.mozilla){//Firefox
			jQuery(this).css('MozUserSelect','none');
		}else if(jQuery.browser.msie){//IE
			jQuery(this).bind('selectstart',function(){return false;});
		}else{//Opera, etc.
			jQuery(this).mousedown(function(){return false;});
		}
	});
});


jQuery.extend(jQuery.fn.beautyfySelect = function() {
	return this.each(function(){
		var select=jQuery(this);
		select.css('display','none').after('<div class="selectReplacement"><div><i></i><b></b><div class="selectReplacementHead"></div><ul></ul></div></div>').find('option').each(function() {
			jQuery(this).parent().next().find('ul').append('<li value="'+jQuery(this).attr('value')+'"'+(jQuery(this).parent().next().find('ul li').length==0?' class="first"':'')+'><a href="#"'+(jQuery(this).attr('selected')?' class="selected"':'')+'>'+jQuery(this).text()+'</a></li>');
			if(jQuery(this).attr('selected')) {
				jQuery(this).parent().next().find('.selectReplacementHead').text(jQuery(this).text());
			}
		});
		select.next().find('ul').width(select.width()+20);
		select.next().find('.selectReplacementHead').width(jQuery(this).parent().find('ul').width()-(jQuery('body.ie7').length?18:28));
		select.next().find('.selectReplacementHead, i, b').click(function(event){
			event.preventDefault();
			jQuery(this).nextAll('ul').attr('skip','true').animate({
				'height':'toggle',
				'opacity':'toggle'
			},'fast',function(){
				if(jQuery(this).css('display')=='block') {
					jQuery(this).attr('skip','false')
				}
			});
		});
		select.next().find('ul li a').click(function(){
			jQuery(this).parents('ul').find('a').removeClass('selected');
			jQuery(this).addClass('selected');
			jQuery(this).parents('.selectReplacement').find('.selectReplacementHead').text(jQuery(this).text());
			jQuery(this).parents('ul').attr('skip','true').animate({
				'height':'toggle',
				'opacity':'toggle'
			},'fast',function(){
				jQuery(this).attr('skip','true')
			});
			jQuery(this).parents('.selectReplacement').prev().find('option').eq(jQuery(this).parents('ul').find('a').index(this)).attr('selected','selected');
			jQuery(this).parents('.selectReplacement').prev()[0].skipUpdate=true;
			jQuery(this).parents('.selectReplacement').prev()[0].simulate('change');
			jQuery('.regular-price .price').text(jQuery('.regular-price .price').text()+'*');
			return false;
		});
		select.next().bind("mouseleave",function(){
			if(jQuery(this).find('ul').css('display')!='none' && jQuery(this).find('ul').attr('skip')=='false')
				jQuery(this).find('ul').animate({
					'height':'toggle',
					'opacity':'toggle'
				},'fast',function(){
					jQuery(this).attr('skip','true')
				});
		});
		if(jQuery().everyTime) {
			jQuery(this).everyTime(1000, 'observer', function() {
//todo: check changes in original select by other js-functions
			});
		}
		select.change(function() {
			if(jQuery(this)[0].skipUpdate) {
				jQuery(this)[0].skipUpdate=false;
				return;

			}
			jQuery(this).find('option').each(function() {
				if(jQuery(this).is(':selected')) {
					jQuery(this).parent().next().find('ul li a').eq(jQuery(this).parent().find('option').index(this)).click();
				}
			});
		});
	});
});

/*



		checkSelectChange = function() {
			if(jQuery('.optionsItem select option').length>jQuery('.optionsItem select').next().find('ul li').length) {
				
			}
		
		}
		
		var optionItemsInterval = window.setInterval("checkSelectChange()", 1000);

*/








jQuery(document).ready(function() {
	var ie6=false;
	
	
if(jQuery.browser.msie && jQuery.browser.version>=7 && jQuery.browser.version<8 ) {
	jQuery('body').addClass('riel7');
}
	
	
//	jQuery(".ie6 #products li:last").css('position','absolute');

	if(jQuery.browser.msie && jQuery.browser.version < 7) {
		ie6=true;
		/*fix für transparente PNGs*/
		DD_belatedPNG.fix('#shoplogo, #rbblogo, #navigation ul li, #home, #leftIcons, #leftIcons div, #leftIcons ul li a, #leftIcons ul li.active span, span#activenupsi, #right .box, #right .box h4, #right .colored .boxContent, #right .box .boxHead, #right .box .boxFooter, a.button .b-tl, a.button .b-tr, a.button .b-bl, a.button .b-br, a.button, a.arrow, #right .search .boxContent form input.submit, #right .sicherheit .boxContent span, #right .search .boxContent, #right .basket h4 span, #products li h4, #products .basket, .prodImg .new, .prodImg .soon, .prodImg .offer, .prodImg span.audio, #products .prodImg span.video, ul.visit li a, ul.visit li div, .legend span, #right .basket .sum, #right .basket .sum div, div.tabs .tab ul li, div.tabs .tab ul li .cart, .listOptions .sortNone, .listOptions .sortAsc, .listOptions .sortDesc, #empfehlung .cart, ul#recentlyViewedProducts li, .cart_menge .remove, .one-page-checkout-progress dt, .sp-methods .divider, .one-page-checkout-progress a, ol.adressbook li .divider, #wishlist td.remove .remove, #tickets .cartIcon, #startseite #tickets .datum, #kokabox img');
		jQuery.rule('#leftIcons ul li a','style').append('top:5px;');
		jQuery.rule('#right .box .boxHead','style').append('top:-1px;');
		jQuery.rule('#right .box .boxFooter','style').append('bottom:-5px;background-position:0 -292px;');/*background-position:0 -283px;*/
		jQuery.rule('#right .box','style').append('width:225px;overflow-x:hidden;');
	}
	else {
		/*replacement für (manche) selectfelder*/
		
		
		
		
		/*
		
		jQuery('#topForm select').each(function(){
			jQuery(this).css('display','none').after('<div class="selectReplacement"><i></i><b></b><div class="selectReplacementHead"></div><ul></ul></div>');
			jQuery(this).find('option').each(function() {
				jQuery(this).parent().next().find('ul').append('<li value="'+jQuery(this).attr('value')+'"'+(jQuery(this).parent().next().find('ul li').length==0?' class="first"':'')+'><a href="#"'+(jQuery(this).attr('selected')?' class="selected"':'')+'>'+jQuery(this).text()+'</a></li>')
				if(jQuery(this).attr('selected'))
					jQuery(this).parent().next().find('.selectReplacementHead').text(jQuery(this).text());
			});
			jQuery(this).parent().find('.selectReplacementHead').width(jQuery(this).parent().find('ul').width()-28);
		});
		jQuery('#topForm .selectReplacementHead,#topForm i, #topForm b').click(function(event){
			event.preventDefault();
			jQuery(this).nextAll('ul').toggle('fast');
		});
		jQuery('#topForm .selectReplacement ul li a').click(function(){
			jQuery(this).parents('ul').find('a').removeClass('selected');
			jQuery(this).addClass('selected');
			jQuery(this).parents('.selectReplacement').find('.selectReplacementHead').text(jQuery(this).text());
			jQuery(this).parents('ul').toggle('fast');
			return false;
		});
		jQuery('#topForm .selectReplacement').bind("mouseleave",function(){
			jQuery(this).find('ul').hide('fast');
		});
		jQuery('.selectReplacement').disableTextSelect();
		
		
		
		
		
		
		checkSelectChange = function() {
			if(jQuery('.optionsItem select option').length>jQuery('.optionsItem select').next().find('ul li').length) {
				
			}
		
		}
		
		var optionItemsInterval = window.setInterval("checkSelectChange()", 1000);
		
*/
		
		jQuery('#topForm select, #optionsBox select').beautyfySelect().next().disableTextSelect();
		
		
		
		
		
		
		
		
		
		
		
	}
	if(jQuery.browser.msie) { //all bad guys
		jQuery('#products .prodImg img').click(function() { //ie rafft den klick auf das bild nicht, da es absolut positioniert ist
			window.location.href=jQuery(this).parents('a').attr('href');
		});
	}
	
	
	
	
	
	
	
	
	
	
	
	
	if(!(jQuery.browser.mozilla && parseFloat(jQuery.browser.version)<=1.8) && !(jQuery.browser.msie && jQuery.browser.version<7)) { /*wenn nicht Firefox 2*/
		/*Hover-Effekte für Media-Icons*/

		jQuery("#leftIcons ul li").not(".active").find('a').each(function(){
			jQuery(this).attr("initialBackgroundColor",jQuery.rule('#leftIcons ul li a','link').css("backgroundColor"));
			jQuery(this).attr("hoverBackgroundColor",jQuery.rule('body'+(jQuery('body').attr('class').replace(' riel7','').replace('ie7','').replace('ie6','').replace('medien','').replace('alletickets','').replace('alleprodukte','').replace(' ','').length?'.':'')+(jQuery('body').attr('class').replace(' riel7','').replace('ie7','').replace('ie6','').replace('medien','').replace('alletickets','').replace('alleprodukte','').replace(' ',''))+' #leftIcons ul li a:hover','link').css("backgroundColor"));
		}).hover(

			function() {
				jQuery(this).stop().css({
					"backgroundColor": jQuery(this).css("background-color")
				}).animate({
					"backgroundColor": jQuery(this).attr("hoverBackgroundColor")
				}, 200);
			},
			function(){
				jQuery(this).stop().css({
					"backgroundColor": jQuery(this).css("background-color")
				}).animate({
					"backgroundColor": jQuery(this).attr("initialBackgroundColor")
				}, 200);
			}
		);

		/*Hover-Effekte für Seitenzahlen*/
		jQuery(".pagination ul li").not(".active").find('a').each(function(){
			jQuery(this).attr("initialBackgroundColor",jQuery.rule('.pagination ul li a','link').css("backgroundColor"));
			jQuery(this).attr("hoverBackgroundColor",jQuery.rule('.pagination ul li a:hover','link').css("backgroundColor"));
		}).hover(
			function() {
				jQuery(this).stop().css({
					"backgroundColor": jQuery(this).css("background-color")
				}).animate({
					"backgroundColor": jQuery(this).attr("hoverBackgroundColor")
				}, 200);
			},
			function(){
				jQuery(this).stop().css({
					"backgroundColor": jQuery(this).css("background-color")
				}).animate({
					"backgroundColor": jQuery(this).attr("initialBackgroundColor")
				}, 200);
			}
		);
		jQuery.rule('.pagination ul li a:hover','link').remove();





		jQuery("input.addToCart").each(function(){
			jQuery(this).after('<a href="#" class="button '+jQuery(this).attr('class')+'">'+jQuery(this).attr('value')+'</a>').next().click(function(){
				productAddToCartForm.submit();
			}).prev().remove();
		});
		jQuery("#newsletter-validate-detail button, #cart button, #discount button, ul.checkout-types li button, .white button, .buttons-set-red button").each(function() {
			switch(jQuery(this).attr("type")) {
				case "button":
					jQuery(this).after('<a href="javascript:" class="button '+jQuery(this).attr('class')+'">'+jQuery(this).find('span').text()+'</a>').next().click(function(){
						jQuery(this).prev().click();
					}).prev().hide();
					break;
				case "submit":
					jQuery(this).after('<a href="javascript:" class="button '+jQuery(this).attr('class')+'">'+jQuery(this).find('span').text()+'</a>').next().click(function(){
						jQuery(this).prev().click();
					}).prev().hide();
					break;
				default:
					break;
			}
		});



		/*Hover-Effekte für Buttons*/
		jQuery("a.button").each(function(){
			jQuery(this).attr("initialBackgroundColor",jQuery(this).css("backgroundColor"));
			var bg=getRGB(jQuery(this).attr("initialBackgroundColor"));
			bg[0]=Math.min(255,bg[0]+20);
			bg[1]=Math.min(255,bg[1]+15);
			bg[2]=Math.min(255,bg[2]+45);
			
			
			if(jQuery(this).hasClass('addToCart') || jQuery(this).parents('#cart, #discount, #shipping, #totals, .white, #newsletter-validate-detail,#tickets').length) {
				bg=[182,177,151];
			}
			
			jQuery(this).attr("hoverBackgroundColor",'rgb('+[bg].join(",")+')');
		}).hover(
			function() {
				jQuery(this).stop().css({
					"backgroundColor": jQuery(this).css("background-color")
				}).animate({
					"backgroundColor": jQuery(this).attr("hoverBackgroundColor")
				}, 100);
			},
			function(){
				jQuery(this).stop().css({
					"backgroundColor": jQuery(this).css("background-color")
				}).animate({
					"backgroundColor": jQuery(this).attr("initialBackgroundColor")
				}, 100);
			}
		);

	}

	/*effekte für media-navigation*/
	jQuery("#leftIcons ul li a span").remove();
	jQuery("body").append('<span id="activenupsi"></span>');

	jQuery("span#activenupsi").css('display','block');
	if(jQuery("#leftIcons ul li.active span").length) {
		jQuery("#leftIcons ul li.active span").css('background','none');
		pos=jQuery('#leftIcons ul li.active span').offset();
		jQuery("span#activenupsi").css('top',pos.top);
	} else {
		jQuery("span#activenupsi").css('left',-10);
	}

	jQuery("#leftIcons ul li a").hover(function(){
		pos=jQuery(this).parent().find('span').offset();
		if(!jQuery("#leftIcons ul li.active span").length && parseInt(jQuery("span#activenupsi").css('left'))<-5) {
			jQuery("span#activenupsi").css('top',pos.top);
		}
		jQuery("span#activenupsi").stop().animate({top:pos.top,left:8},500,'swing');
	},function(){
		if(jQuery("#leftIcons ul li.active span").length) {
			pos=jQuery('#leftIcons ul li.active span').offset();
			jQuery("span#activenupsi").stop().animate({top:pos.top},500,'swing');
		} else {
			jQuery("span#activenupsi").stop().animate({left:-10},'fast','swing');
		}
	});


	/*runde ecken für buttons*/
	jQuery("a.button").append('<div class="b-tl"></div><div class="b-tr"></div><div class="b-bl"></div><div class="b-br"></div>');
	jQuery("a.addToCart, #tickets a.button").append('<div class="cartIcon"></div>');

	/*effekte für hauptnavigation*/
	jQuery('#navigation>ul').superfish({ 
		animation:   {opacity:'show'/*,height:'show'*/},  // fade-in and slide-down animation 
		speed:       'fast',                          // faster animation speed 
		autoArrows:  false
	}).find('ul').bgIframe(); 

	/*submenü des letzten hauptmenüpunkt wird an maximale breite angepasst*/
	/*
	var left=jQuery('#navigation>ul>li:last').position().left;
	var width=jQuery('#head').width()-left+2;
	jQuery('#navigation>ul>li:last ul').width(width);
	*/

	/*legende wird eingefügt*/
	if(jQuery('.legend').length) {
		if(jQuery('#products .prodImg span.video').length)
			jQuery('.legend').prepend('<span class="video">Videovorschau</span>');
		if(jQuery('#products .prodImg span.audio').length)
			jQuery('.legend').prepend('<span class="audio">Hörprobe</span>');
	}

	/* startseite tabs mit scrollbar*/
	var tabContainers = jQuery('div.tabs > div');
	jQuery('div.tabs ul.tabs a').click(function () {
		jQuery(this).blur();
		tabContainers.jScrollPaneRemove();
		tabContainers.hide().filter(this.hash).show().jScrollPane({showArrows:true,wheelSpeed:100});
		jQuery('div.tabs ul.tabs li').removeClass('selected');
		jQuery(this).parents('li').addClass('selected');
		jQuery('div.tabs ul.tabs li').removeClass('indent-left').not('.selected, :first').addClass('indent-left');
		jQuery('div.tabs ul.tabs li').removeClass('indent-right').not('.selected, :last').addClass('indent-right');
		jQuery('.tabs .allArticles').css('display',((this.hash=='#angebote')?'block':'none'));
		return false;
	}).filter(':first').click();

	/*container auf der startseite bekommen "alle artikel" link und die breite des tabs wird angepasst*/
	jQuery('#startseite #products h3 a').each(function() {
		jQuery(this).width(Math.max(jQuery(this).width(),jQuery('#empfehlung h2 b').width()));
		jQuery(this).parents('li').append('<a href="'+jQuery(this).attr('href')+'" class="allArticles">alle Artikel</a>');
	});
	
	
	
	jQuery("#productDetailLeft a").fancybox({
		'hideOnContentClick': false
	});
	
	

   jQuery("#content a[href^='http://'],#content a[href^='https://']").not("a[href^='http://"+window.location.host+"'],a[href^='https://"+window.location.host+"']").not("a[href^='http://www."+window.location.host+"'],a[href^='https://www."+window.location.host+"']").click(function(){
      window.open(this.href);
      return false;
   });
   
   
   

   jQuery("#navigation li.hasChildren:not(:has(ul))").removeClass("hasChildren");
   
   jQuery("#orders_history_detail_items table tr td.divider:last").addClass("dividerLast");

   
   
   if(jQuery(".pagination").length>0 && jQuery(".pagination li").length==0) {
   	jQuery(".legend").css("padding-top",0);
   }
	
	if(jQuery(".ie6").length>0) {
		jQuery("body").addClass(jQuery("body").attr('class').replace("ie6","").replace('medien','').replace('alletickets','').replace('alleprodukte','').replace(" ","")+"ie6");
	}
	
	var packstring='Packstation [Bitte Nummer eingeben!]';
	var packstring_short='Packstation ';
	jQuery('#packstationinfo').click(function(){
		jQuery('.packstationinfo, #packstationfinder').toggle();
		jQuery('.packstationinfo:previousSbiling').prev().toggle();
		if(jQuery('.packstationinfo:first').css('display')!='none') {
			if(document.getElementById('shipping:street1').value.length==0) {
				document.getElementById('shipping:street1').value=packstring;
			}
			jQuery('#packstationinfo').text("Versand an eine andere Lieferadresse?");
		}
		else {
			if(document.getElementById('shipping:street1').value==packstring) {
				document.getElementById('shipping:street1').value='';
			}
			jQuery('#packstationinfo').text("Versand an eine Packstation?");
		}
	});
	jQuery('#shipping_street input').focus(function() {
		if(document.getElementById('shipping:street1').value==packstring) {
			document.getElementById('shipping:street1').value=packstring_short;
		}
	});
	jQuery('#shipping_street input').blur(function() {
		if(document.getElementById('shipping:street1').value==packstring_short) {
			document.getElementById('shipping:street1').value=packstring;
		}
	});

	
	/*
	
			jQuery("#productDetailLeft a").fancybox({
				'padding':4,
			  'imageScale': true,
		    'zoomOpacity': true,			  
        'hideOnContentClick': true, 
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300,
		    'zoomSpeedChange': 300,        
		    'overlayShow':	true,
		    'overlayOpacity':	0.8,
		    'hideOnContentClick':	false,
		    'centerOnScroll':	true,
		    'easingIn':	'swing',
		    'easingOut':	'swing',
		    'easingChange':	'swing'                       
      });	
	
*/
});

function displayTopic(obj) {
	var val=obj.options[obj.options.selectedIndex].value;
	var vals=val.split(';');
	if(vals.length==1)
		window.location.href=val;
	return false;
}
