resize_handle=null;

try
{
    var appender;
    log = log4javascript.getLogger("main");
    appender = new log4javascript.InPageAppender();
    log.addAppender(appender);
    log.debug('Debug started here::');
} catch(e){}







$(document).ready(
    function() {

        $.fn.colorbox.init()


        // clear input box on focus
        $("#input_search").bind('focus', function(e) {
            e.target.value = '';
        } );

        // clear input box on focus
        $("#search_button").bind('click', function(e) {
            var q=$("#input_search").value();
            window.open('http://www.google.com/search?q='+q+'&sitesearch=dialyse-holidays.de','search');
            e.preventDefault();
            e.stopPropagation();
        } );

        $('#select_other_land').bind('change',function(e){
            var land_id=(e.target.value);
            window.location = '/land/'+land_id+'/?q='+'/reiseinformationen/reiseinfos-012009/';
        });
        
        $('#select_other_city').bind('change',function(e){
            var land_id=(e.target.value);
            window.location = '/city/'+land_id+'/?q='+'/feriendialysen/städtereise/';
        });

        $('h2.list_head_closed').click(function(e)
        {
            $(e.target).siblings('div.list_of_centers').slideToggle(700);
            $(e.target).toggleClass('list_head_open')
            $(e.target).toggleClass('list_head_closed')
        });


        //    $('ul').parent('strong').mousedown(function(e)
        //    {
        //        $(e.target).siblings('').slideToggle(400);
        //    });



 

        // collapsible names for Ship lists
        if(String(window.location).search(/termine-routen/)!=-1)
        {
            $('#contentLeft ul').css({
                display:'none'
            });
            $('#contentLeft strong').click(function(e){
                $(e.target).parent().next('ul').slideToggle(700);
                $(e.target).toggleClass("ship_header_open");
                $(e.target).toggleClass("ship_header_closed");
            });
            $('#contentLeft strong').addClass('ship_header_closed')
        }


        //$('#admin_edit_tag').css({display:'none'});
        //$('#admin_edit_tag').fadeIn(900);



        // rating stars (in DIV table with star PNGs)
        // 2009.08.13
        $('div#rating table img').click(function(e){
            var t=$(e.target);
            var active='/media/style/star.png';
            var in_active ='/media/style/star2.png';
            $(t).attr('src',active);
            $(t).prevAll('img').attr('src',active);
            $(t).nextAll('img').attr('src',in_active);
            var index = $(t).parent().children('img').index(t) + 1;
            $(t).parent().children().val(index);
        });



        //$('#btn_rate').click(rate_function);

        center_rating();

        $('#btn_show_rating').click(function(e){
            center_rating();
            $('div#rating').fadeIn(500);
        });

        $('#btn_cancel_rating').mousedown(function(e){
            $('div#rating').fadeOut(500);
        });

        $(window).resize(function(e){
            /// in IE window resize is fired multiple times
            /// that can kill the browser
            clearTimeout(resize_handle);
            resize_handle=null;
            resize_handle=setTimeout('center_rating()', 50);
        });

        $('a.hotel_info_mehr_info').css({cursor:'pointer'});
        $('a.hotel_info_mehr_info').click(function(e){

            $(e.target).closest('div').children('span.short_version').css({display:'none'});
            $(e.target).closest('div').children('span.long_version').fadeIn(700);
            $(e.target).hide();

        });

        $('a.hotel_info_mehr_info_close').css({cursor:'pointer'});
        $('a.hotel_info_mehr_info_close').click(function(e){

            $(e.target).closest('div').children('span.short_version').fadeIn(700);
            $(e.target).closest('div').children('span.long_version').css({display:'none'});            
            $('a.hotel_info_mehr_info').show();
            
        });



        $("a[rel='slideshow']").colorbox({
            transition:"elastic",
            maxWidth:'80%',
            maxHeight:'80%'
        });




    });




function center_rating() {
    // center hidden rating DIV
    var _x = ($(window).width() - $('div#rating').width())/2;
    $('div#rating').css({
        'left':_x+'px'
    });
}

function rate_function(e) {
    var valid=true
    valid &= $('div#rating #rate_name').val().length >= 2;
    valid &= $('div#rating #rate_ort').val().length >= 2;
    valid &= parseInt($('div#rating input[name="r1"]').val()) >= 1;
    valid &= parseInt($('div#rating input[name="r2"]').val()) >= 1;
    valid &= parseInt($('div#rating input[name="r3"]').val()) >= 1;
    valid &= parseInt($('div#rating input[name="r4"]').val()) >= 1;
    valid &= parseInt($('div#rating input[name="r5"]').val()) >= 1;
    if(!valid)
    {
        alert('Please correct the formula! (Error)');
    }
    else
    {
        $('#rate_form').submit();
    }
}








