$(document).ready(function(){
	
	/* Kleines Dropdown für Filter usw. */
	
	$('.dropdown-menu').click(function() {
		
		if( $('.menu-first', this).hasClass('selected') ) {
			
			pageClick();
			
			$('.menu-first', this).removeClass('selected');
 	  		$('input', this).val('');
   	  	$('#_filterlist').submit();
			
		} else if ( $('.menu-first', this).hasClass('slide-down')  ) {
		
		  	pageClick();
		
		  	$('.menu-first', this).removeClass('slide-down'); 
		  	$('.down-list', this).hide();
			
		} else {
			
			pageClick("on");
			
			$('.menu-first', this).addClass('slide-down'); 
			$('.down-list', this).show();
			
		
			
		}	
	});
		
		
	/* Dropdown für Detailseite */
	
	$('.dropdown125-menu').click(function() {
		
	 if ( $('.down-list', this).css('display') == 'none' ) {
	
		  pageClick("on");
		  
		  $('.menu-first', this).addClass('slide-down'); 
        $('.down-list', this).show();
			$(this).css("z-index", $(this).css("z-index") - (-500) );
			

		} else {
			
		  $('.menu-first', this).removeClass('slide-down'); 
        $('.down-list', this).hide();
        $(this).css("z-index", $(this).css("z-index") - (500) );
			
			pageClick();
			
		}	
	});
	
	

	
	/* Größe Dropdowns */
	
	$('.dropdown425-menu').click(function() {
		
		if ( $('.down-list', this).css('display') == 'none' ) {
		 
		  pageClick("on");
		  
		  $('.menu-first', this).hide();
        $('.down-list', this).show();
			

		} else {
			
			pageClick();
		
		  $('.menu-first', this).show();
        $('.down-list', this).hide();
			
		
			
		}	
	});
	
	
	$('.dropdown115-menu').click(function() {
		
		if ( $('.down-list', this).css('display') == 'none' ) {
		
		  pageClick("on");
		  
		  $('.menu-first', this).hide();
        $('.down-list', this).show();
			

		} else {
			
			pageClick();
		
		  $('.menu-first', this).show();
        $('.down-list', this).hide();
			
		
			
		}	
	});
	
	
	$('.dropdown90-menu').click(function() {
		
		if ( $('.down-list', this).css('display') == 'none' ) {
			
		 	pageClick("on");
			
			$('.menu-first', this).hide();			
			$(this).css("z-index", "1500");
        	$('.down-list', this).show();
			$(this).css("top", "-150px" );
			
		} else {
			
			pageClick();
			
			$('.menu-first', this).show();
        	$('.down-list', this).hide();
        	$(this).css("z-index", "1000");
			$(this).css("top", "0px" );
			
		}
	});
			
			
	/* Reload Dropdown */
		
	$(".dropdown-menu a").click(function() {
			
			$(this).parent('.down-list').hide();
			
			var dropdown = $(this).parent().parent('.dropdown-menu');
			$('.menu-first', dropdown).text(  $(this).text() );
			$('input', dropdown).val(  $(this).text() );
		
	});
  
  
	/* Popup */
  	
	$(".popup .btn1").click(function() {
				showPopupContent(1);													 
	});
	
	$(".popup .btn2").click(function() {
				showPopupContent(2);													 
	});
	
	$(".popup .btn3").click(function() {
				showPopupContent(3);													 
	});
	
	
	/* Form Values */
	
	 $("#newsletter_txt").blur(function () {
        if( $(this).val() == "") {
				$(this).val('Ihre E-Mail-Adresse');
		  }
    });
	 
	 
	 $("#newsletter_txt").focus(function () {
        if( $(this).val() == "Ihre E-Mail-Adresse") {
				$(this).val('');
		  }
    });
	 
	
	
	
	/* Flyout Menue */
	
	$('#main_navigation a').hover(
		function () {
     		
				main_navi_over(this.id);
				
				
      }, function () {
       
			 	main_navi_out(this.id);
				 
      }
    );
		
	
	$('.flyout').hover(
		function () {
     		
				flyout_over( this.id.substr(7) );
				
      }, function () {
       
			 	main_navi_out( this.id.substr(7) );
			 
      }
    );
	
	// Zoom
	
	var options = {
	    zoomWidth: 351,
	    zoomHeight: 350,
       xOffset: 50,
       yOffset: 0,
		 title: false,
       position: "right" //and MORE OPTIONS
	};
	
	$('.jqzoom').jqzoom(options);

	
	
	
});

function setDropdown(dropdownLink) {
	
	var dropdown = $(dropdownLink).parent().parent('.dropdown_standard');
		
	var dropdown_txt;
	var hiddenfield_txt;

	switch (arguments.length) {

		case 2:
			dropdown_txt = $(dropdownLink).text();
		 	hiddenfield_txt = arguments[1];
			break;
		
		case 1:
		default:
			dropdown_txt = hiddenfield_txt  = $(dropdownLink).text();

	}
	
	$('.menu-first', dropdown).text(  dropdown_txt );
	$('input', dropdown).val(  hiddenfield_txt );
		
}

function pageClick(status) {
	
	if(pageClick.arguments[0]) {
		status = pageClick.arguments[0];
	}
	
	$('.page').unbind('click'); 	
	dropdownClicks = 0;
	
	hideAllDropdowns();
	
	if(status=="on") {
	
			$('.page').click(function() {
			
				if(dropdownClicks==1) {
					
					$('.page').unbind('click'); 	
					dropdownClicks = 0;
					
					hideAllDropdowns();
							
				} else {
					dropdownClicks = 1;
				}
					
			})
	}

}

function hideAllDropdowns() {
	
	/* Basket */
	$('.dropdown-menu .menu-first').removeClass('slide-down');

	/* Filter */
	$('.filters .menu-first').removeClass('slide-down'); 
	
	/* Detail */
	$('.page').find('.dropdown125-menu').each(function(i) {
    	
		if( $('.down-list', this).css('display') != 'none' ) {
		
	 		$('.menu-first', this).removeClass('slide-down'); 
			$(this).css("z-index", $(this).css("z-index") - (500) );
		}
 	});
	
	/* Forms */
 	$('.dropdown425-menu .menu-first').show();
	
	$('.dropdown115-menu .menu-first').show();
	
	/* Payment Form */
	$('.dropdown90-menu .menu-first').show();
	$('.dropdown90-menu').css("z-index", "1000");
	$('.dropdown90-menu').css("top", "0px" );
	
	// Hide all Dropdown Lists
	$('.down-list').hide();
	
}



/* Infoboxen und Impressum */

function showPopupContent(page) {
	
		$('.popup #content_1').hide();
		$('.popup #content_2').hide();
		$('.popup #content_3').hide();
		
		$('.popup #content_' + page).show();
		
		switch (page) {
			case 1:
				$('.popup .btns').css("background-position", "0px 0px" );
				break;
				
			case 2:
				$('.popup .btns').css("background-position", "0px 98px" );
				break;
				
			case 3:
				$('.popup .btns').css("background-position", "0px 49px" );
				break;
		}
		
		$('.popup .btns a').removeClass('selected')
		$('.popup .btn' + page).addClass('selected');
		
}

function popup() {	
	var OpenWindow=window.open("popup.html", "popup","width=510, height=581"); 
}

function showInfoboxContent(page) {
	
		$('.infobox #content_1').hide();
		$('.infobox #content_2').hide();
		$('.infobox #content_3').hide();
		
		$('.infobox #content_' + page).show();
		
		switch (page) {
			case 1:
				$('.infobox .header').css("background-position", "0px 0px" );
				break;
				
			case 2:
				$('.infobox .header').css("background-position", "0px 98px" );
				break;
				
			case 3:
				$('.infobox .header').css("background-position", "0px 49px" );
				break;
		}
		
		$('.infobox .header a').removeClass('selected')
		$('.infobox .btn' + page).addClass('selected');
		
}


/* Flyout Menue */

function main_navi_over(id) {
		
		mouseOvers++;
			
		btn_out('main_cat_01');
		btn_out('main_cat_02');
		btn_out('main_cat_03');
		btn_out('main_cat_04');
		btn_out('main_cat_05');
			
		$('#' + id).css("background-position", "0px 50px" );
		
		$('#flyout_main_cat_01').hide();
		$('#flyout_main_cat_02').hide();
		$('#flyout_main_cat_03').hide();
		$('#flyout_main_cat_04').hide();
		
		
		if(id != 'main_cat_05') {
				
				if(flyouts_on == true) { 
					$('#flyout_' + id).show();
				} else {
					$('#flyout_' +id).show();
					flyouts_on = true;
				}
				
		}
}

function flyout_over(id) {
			
		$('#' + id).css("background-position", "0px 50px" );
		
		mouseOvers++;
}

function btn_out(id) {
	
 	if ( $('#' + id).hasClass("selected") ) {
		$('#' + id).css("background-position", "0px 100px" );
		
	} else {
		
		$('#' + id).css("background-position", "0px 0px" );
	}
	
}

function main_navi_out(id) {
		
	 	$(this).delay(10,function(){
			
			mouseOuts++;
			
			if(mouseOvers == mouseOuts) {
				
				flyouts_on = false;
				
				$('#flyout_' + id).hide();
				btn_out(id);
				
				//fix für Bug bei schneller Mausbewegung
				
				if(id != 'main_cat_01') 	{ $('#flyout_main_cat_01').hide(); }
				if(id != 'main_cat_02') 	{ $('#flyout_main_cat_02').hide(); }
				if(id != 'main_cat_03') 	{ $('#flyout_main_cat_03').hide(); }
				if(id != 'main_cat_04') 	{ $('#flyout_main_cat_04').hide(); }
				
					
			}
		});
}

function setValueOnId(elId, iSelIdx){
	$(elId).val(iSelIdx);	
}

function setFormActionUrl(elId, sActionUrl){
	$(elId).attr('action', sActionUrl);
}
// OXID compatibility for setting selectlists on noticelist/wishlist href attribute
// comp. oxid.js
function sr_setSellList( sName, sValue)
{
    //for module wlist
    var _wlist = document.getElementById("wlist");
    if ( _wlist !== null) {
        _wlist.href = _wlist.href + "&" + sName + "=" + sValue;
    }
    //for original selectlist
    var _slist = document.getElementById("slist");
    if ( _slist !== null) {
        _slist.href = _slist.href + "&" + sName + "=" + sValue;
    }
}
function fbs_click() {

	u=location.href;
	u = u.replace(/sid\/.*?\//,"");					
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0 ,status=0,width=626,height=436');
	return false;
}

function sfl(sElId, sCatRootId, sCatId, sGender, sActionUrl){
	document.getElementById(sElId).href = "javascript:" +
    		"$('#filter_maincat').val('"+sCatRootId+"');" +
    		"$('#filter_cnid').val('"+sCatId+"');" +
    		"$('#filter_gender').val('"+sGender+"');" +
    		"document.forms['_filterlist_flyout'].action=\""+sActionUrl+"\";" +
    		"document.forms['_filterlist_flyout'].submit();";
}
function sUrl(sElId, sActionUrl){
	document.getElementById(sElId).href = sActionUrl;
    		
}



var flyouts_on = false;
var mouseOvers = 0;
var mouseOuts = 0;
var dropdownClicks = 0;
