$(document).ready(function(){

    // fix modelle link
    $('li.page-item-13 a').attr('href', '/modelle');

    // fix header link
    $('#headerimg h1 a').attr('href', '/modelle');
    
    // fix zimmer menu highlighting
    if(location.href.match(/\/zimmer\//)){
        $('#menu li:nth-child(2)').addClass('current_page_item');
    }

    // handle comment form visibility
    $('#new_comment').click(function(){
        $('#commentform').fadeIn('slow')
        return false;
    });

    //img protection
    $('img').bind('contextmenu',function(){return false;});

    // bind specials layer logic
    $('#specials').click(function(){
        if($('div.specials').is(':visible')) {
            $('div.specials').fadeOut();
        } else {
            $('div.specials').fadeIn();
        }
        return false;
    });
	$('div.specials').click(function(){
		$(this).fadeOut();
	});
    
    // bind click on showcase link width null 
    $('div#showcase div#spotlight div.content a').click(function() {
        return false;
    });

    // enable rating feedback
    $('div.post-ratings').click(function(){
        $(this).html('<p style="text-align:center"><strong>Vielen Dank&nbsp;</strong></p>');
    });

    // enbable model mouseover zoom effect
    $('li.modell a').hover(
        function(){
            var link = $(this);
            var ratings = link.find('div.hoverratings');
            var name = link.find('span.name');
            name.addClass('auto');
            link.addClass('zoom');
            ratings.removeClass('hidden');
            ratings.hover(
                function(){
                    link.click(function(){
                        ratings.html('<p style="text-align:center"><strong>Vielen Dank</strong></p>');    
                        return false;
                    });
                },
                function()  {
                    link.unbind('click');
                }
            );
        },
        function() {
            var link = $(this);
            var ratings = link.find('div.hoverratings');
            var name = link.find('span.name');
            name.removeClass('auto');
            link.removeClass('zoom');
            ratings.addClass('hidden');
        }
    ); 

    // enable showcase gallery system
    $($('#showcase #spotlight div.content img').get(0)).fadeIn();
    $('#gallery ul li a').click(function(){
        $('#spotlight img').hide();
        $('#spotlight img[src$='+$(this).find('img').attr('src').replace(/\-150+x150/,'')+']').show();
        return false;
    });

    // bind teaser box navi logic
    $('#teasernavi_left').click(function(){
        if($('#box_1').is(':hidden')) {
           $('#box_4').addClass('hidden');
           $('#box_1').removeClass('hidden'); 
        } else if($('#box_0').is(':hidden')) {
           $('#box_3').addClass('hidden');
           $('#box_0').removeClass('hidden'); 
        }
        return false;
    });
    $('#teasernavi_right').click(function(){
        if($('#box_3').is(':hidden')) {
           $('#box_0').addClass('hidden');
           $('#box_3').removeClass('hidden'); 
        } else if($('#box_4').is(':hidden')) {
           $('#box_1').addClass('hidden');
           $('#box_4').removeClass('hidden'); 
        }
        return false;
    });  

	// LP image fade
	if($('#landingpage').length){
		var interval = setInterval(function(){
			if($('img.fade').first().is(':hidden')) {
				$('img.fade').first().fadeIn('slow');
			} else if($('img.fade').first().next().is(':hidden')) {
				$('img.fade').first().fadeOut('slow');
				$('img.fade').first().next().fadeIn('slow');
			} else if($('img.fade').first().next().next().is(':hidden')) {
				$('img.fade').first().next().fadeOut('slow');
				$('img.fade').first().next().next().fadeIn('slow');
			} else if($('img.fade').first().next().next().next().is(':hidden')) {
				$('img.fade').first().next().next().fadeOut('slow');
				$('img.fade').first().next().next().next().fadeIn('slow');
			} else {
				$('img.fade').fadeOut('slow');
			}
		},7500);
	}  

	// newsletter status
	if(location.hash === '#danke') {
		alert('Vielen Dank fürs eintragen - bald kommt erste Post!');
		location.hash='';
	} else if(location.hash === '#problem') {
		alert('Diese Emailadresse scheint nicht gültig zu sein');
		location.hash='';
	}
});
