var all_open = false;

$(document).ready(function() {
    var hash = window.location.hash;
    
    (!hash) ?  
        hideAllExcept('#' + $('ul#verlauf > li:first').attr('id')) 
            : hideAllExcept(window.location.hash);

    $('a.toggle').click(function() {
        
        var href = $(this).attr('href');
        toggle(href);return false;
        //hideAllExcept(href);
    });
    
    toggle_all();
});

function hideAllExcept(el) {
    if(!$(el).hasClass('open')) {
        //$().animate({},"fast", "linear", function() {
            $('ul#verlauf li.open').removeClass('open');
            $('ul#verlauf li.open').removeAttr('style'); // !important
        //});
        $('ul#verlauf li').addClass('closed');
        $(el).removeClass('closed');
        //$(el).attr('style', 'height:49px')
        $(el).addClass('open')
        //$().animate({height: '175px'}, "fast", "linear", function() {
        $(el).removeAttr('style')
        
        //})
        //$(el).addClass('open');
        //$('ul#main li').removeClass('open');
        //$('a[href="' + el + '"]').addClass('open');
    }
}

function loadPic(url, txt, width) {
    n_width = '267px';
    if(width == 259) {
        n_width = '267px';
    }
    if(width == 118) {
        n_width = '126px';
    }

	$('img#galerie-main').attr('src',url);
	$('#galerie-main-container').css('width',n_width);
	$('div#galerie-main-caption').html(unescape(txt))
}

function toggle(el) {
    if(!$(el).hasClass('open')) {
        $(el).addClass('open');
    }else{
        $(el).removeClass('open');
    }
}

function open_all() {
    $('ul#verlauf li').each(function(){
        if(!$(this).hasClass('open')) {
            $(this).addClass('open')
        }
        if($(this).hasClass('closed')) {
            $(this).removeClass('closed')
        }
    })
}

function close_all() {
    $('ul#verlauf li').each(function(){
        if($(this).hasClass('open')) {
            $(this).removeClass('open')
        }
        if(!$(this).hasClass('closed')) {
            $(this).addClass('closed')
        }
    })
}



function toggle_all(el) {
    if(all_open) {
        close_all()
        all_open = false;
        $('.toggle-all-link').each(function(){ this.innerHTML = 'alles aufklappen'});
    }else{
        open_all()
        all_open = true;
        $('.toggle-all-link').each(function(){ this.innerHTML = 'alles zuklappen'});
    }
    return false;
}

function next_pic(){
	var el = $('#pic-strip')
	var oldmargin = el.css('margin-left')
	el.css('margin-left', parseInt(oldmargin) - 90 + 'px')
}
function prev_pic() {
	var el = $('#pic-strip')
	var oldmargin = el.css('margin-left')
	if(parseInt(oldmargin) < 0){
		el.css('margin-left', parseInt(oldmargin) + 90 + 'px')
	}
}

function close_open(uid) {
    var href = $('#'+uid+'-pic').parent().get(0).href
    tb_remove()
    setTimeout(function(){
        tb_show(null,href,'hotel-'+uid)
    }, 1500)
}

function close_open_poi(uid) {
    var href = $('#'+uid+'-pic').parent().get(0).href
    tb_remove()
    setTimeout(function(){
        tb_show(null,href,'poi-'+uid)
    }, 1500)
}

function open_parent_lightbox(uid) {
    window.parent.close_open(uid)
}

function open_parent_lightbox_poi(uid) {
    window.parent.close_open_poi(uid)
}
