$(document).ready(
	function()
		{
			
			/* Inaktiver Kaufen-Button / Liste */
			$('.inact', '.teaser').bind(
				'mouseover',
				function() {
					$(this).parents('.teaser').children().find('.menu-first').addClass('alert');
				}
			).bind(
				'mouseout',
				function() {
					$(this).parents('.teaser').children().find('.menu-first').removeClass('alert');
				}
			).click(
				function() {
					$(this).parents('.teaser').children().find('.dropdown125-menu').click();
					
					return false;
				}
			)
			
			/* Aktiver Kaufen-Button / Liste */
			$('.act', '.teaser').bind(
				'mouseover',
				function() {
					$(this).parents('.teaser').children().find('.time').show();
				}
			).bind(
				'mouseout',
				function() {
					$(this).parents('.teaser').children().find('.time').hide();
				}
			);
			
			/* Inaktiver Kaufen-Button / Detail */
			$('.inact', '.information').bind(
				'mouseover',
				function() {
					$('.menu-first', '.options .dropdown125-menu').addClass('alert');
				}
			).bind(
				'mouseout',
				function() {
					$('.menu-first', '.options .dropdown125-menu').removeClass('alert');
				}
			).click(
				function() {
					$('.dropdown125-menu', '.options').click();
					
					return false;
				}
			)
	
	
	
	
    /* Kaufen-Button einschalten */
    $('.down-list > a').click(
        function() {
            var parent = $(this).parents('div.dropHolder').parent();
			
            setTimeout(
                function() {
                    parent.find('a.inact').fadeOut(
                        250,
                        function() {
                            parent.find('a.act').fadeIn();
                        }
                        );
                },
                250
                );
        }
        );
	

    /* 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() {
		
		var dropdown = this;
		
        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();
			
		
        }
		
		$('.page').find('.dropdown425-menu').each(function(i) {
			if(dropdown != this) {
				$(this).addClass('lowerZindex');
			}
		});
		
		$('.page').find('.dropdown90-menu').each(function(i) {
			if(dropdown != this) {
				$(this).addClass('lowerZindex');
			}
		});
		

				
    });
	
	
    $('.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() {
		
		var dropdown = this;
		
        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" );
			
        }
		
		$('.page').find('.dropdown425-menu').each(function(i) {
			if(dropdown != this) {
				$(this).addClass('lowerZindex');
			}
		});
		
		$('.page').find('.dropdown90-menu').each(function(i) {
			if(dropdown != this) {
				$(this).addClass('lowerZindex');
			}
		});
		
		
    });
			
			
    /* Reload Dropdown */
		
    $(".dropdown-menu a").click(function() {
			
        $(this).parent('.down-list').hide();
			
        var dropdown = $(this).closest('.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 zoom = $("#main").find('.jqzoom');
	if(zoom.length){ 
	    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).closest('.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').removeClass('lowerZindex');
    $('.dropdown425-menu .menu-first').show();
	
    $('.dropdown115-menu .menu-first').show();
	
    /* Payment Form */
	$('.dropdown90-menu').removeClass('lowerZindex');
    $('.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;
    }
}

// handle facebook sharer link
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;
}

// handle top bottom agb checkboxes
function handleAGBBoxes(el, id){
    if($(el).attr('checked')){
        $('#'+id).attr('checked', true);
        $('#ord_agb').val(1);
    }else{
        $('#'+id).attr('checked', false);
        $('#ord_agb').val(0);
    }    
}

var flyouts_on = false;
var mouseOvers = 0;
var mouseOuts = 0;
var dropdownClicks = 0;

