$(function(){
    $('.select').selectbox({});

    if(!$.cookie("age")) {
        loadPopup();
    }

    // Rechtsklick
    $(document).bind("contextmenu",function(e){
        return false;
    });
	    
    // Klickrahmen
    $("a").focus(function(){
        $(this).blur();
    });
	
    // Suche
    $("#showSearchForm").click(function() {
        $("#searchForm").slideToggle('normal');
    });

    // VIP Marquee
    $("#wrap_marquee").marquee('marquee');

    if($("#searchSex").val() == 2) {
        $("#searchBreasts input").attr("checked", "");
        $("#searchBreasts input").attr("disabled", "disabled");
        $("#searchBreastsNone").attr("checked", "checked");
    }
    $("#searchSex").change(function(){
        if($(this).val() == '2') {
            $("#searchBreasts input").attr("checked", "");
            $("#searchBreasts input").attr("disabled", "disabled");
            $("#searchBreastsNone").attr("checked", "checked");
        } else {
            $("#searchBreasts input").attr("disabled", "");
        }
    });
	
    // Dropdowns
    $(".fake_select").click(function(){
        var el = $(this).attr("rel");
        $("#" + el).slideToggle("fast");
        if(el == "service_cloud") {
            $("#city_cloud").slideUp("fast");
        } else {
            $("#service_cloud").slideUp("fast");
        }
    });
	
    // Left menu mouseover / mouseout
    $("#categories a").mouseover(function() {
        $(this).css('border-bottom', '1px solid #fff');
        $(this).next().css('border-top', '0');
        $(this).css('margin-right', '0');
        $(this).next().css('margin-right', '0');
    });
    $("#categories a").mouseout(function() {
        $(this).css('border-bottom', '0');
        $(this).next().css('border-top', '1px solid #fff');
        $(this).css('margin-right', '6px');
        $(this).next().css('margin-right', '6px');
    });

		// Telefonnummern Klicks loggen
		// Nummern verstecken
		$("b.phone").each(function() {
			$t = $(this);
			$t.after("<a style='color:#e4c641;text-decoration:underline' href='javascript:void(0)' class='sPhone'>Telefonnummer anzeigen</a>");
			$t.hide();
				$("a.sPhone").click(function() {
					$name = $("h1").html();
					$("a.sPhone").hide();
					$("b.phone").show();
					pageTracker._trackEvent('Modell', 'Telefonnummer anzeigen', $name);
				});
		});
		
});

$.fn.extend({
        marquee: function(id) {
                var $el = $("#" + id);
                var $firstChild = $el.children(":first");
                var $secondChild = $el.children(":nth-child(2)");
                var $step = (parseFloat($firstChild.css('width')) * -1 -12);
    //            alert($step);

                $el.mouseover(function() {
                        $stop = true;
                });

                $el.mouseout(function() {
                        $stop = false;
                });
                                
                var $left = parseFloat($el.css('left'));
                
                if($left == 0) {
                        $firstChild.clone().appendTo($el);
                }

/*
                if($left && $left == ($step / 2)) {
      						$secondChild.clone().appendTo($el);
                }
*/
                if($left && $left < 0 && $left % $step == 0) {
     			$secondChild.clone().appendTo($el);
                        $firstChild.remove();
                        $left = 0;
                }

                if($stop != true) {
                        --$left;
                        $el.css('left', $left.toString() + 'px');
                }
                
                window.setTimeout(function() {$("#wrap_marquee").marquee(id);}, 40);
        }       
});

function setPopupCookie() {
    var $cookieOptions = {
        path: "/"
    };
    var $cookieName = "age";
    $.cookie($cookieName, "over", $cookieOptions);
    disablePopup();
}

function loadPopup() {  
    if($popupStatus==0) {
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
        $popupStatus = 1;
        centerPopup();
    }
}

function disablePopup() {  
    if($popupStatus==1){
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow");
        $popupStatus = 0;
    }
}

function centerPopup() {
    if($.browser.msie && parseInt(jQuery.browser.version) < 7) {
        var windowWidth = $("body").innerWidth();
        var windowHeight = $("body").innerHeight();
    } else {
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
    }
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();
    $("#popupContact").css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2,
        "left": windowWidth/2-popupWidth/2
    });
    $("#backgroundPopup").css({
        "height": windowHeight
    });
}

$(window).load(function(){
    placeNew();
});

function placeNew() {
    // Neu-Overlay
    $(".contact .img:has(.overlayNew)").each(function(e) {
        $(".overlayNew", $(this)).css("left", $("img", $(this)).position().left + "px");
        //		$("img", $(this)).css("border-color", "#d15d50");
        $(".overlayNew", $(this)).show("slow");
    });
}

var $stop = false;
var $popupStatus = 0;  
