var Ischiaprenotazioni = Ischiaprenotazioni || {};


Ischiaprenotazioni.tooltip = function(){
    $('div.tooltip_content').each(function(){
	$(this).hide();
    });
    
    $('.tooltip').each(function(){
	$(this).qtip({
	    content: $('div.tooltip_content', $(this)).html(), // Give it some content, in this case a simple string
	    style: {
		background: '#FFBB00',
		color: 'black',
		width: 'auto',
		padding: 5,
		textAlign: 'center',
		border: {
		    width: 7,
		    radius: 5,
		    color: '#FFBB00'
		},
		tip: 'bottomLeft',
		name: 'dark' // Inherit the rest of the attributes from the preset dark style
	    },
	    position: {
		corner: {
		    target: 'topRight',
		    tooltip: 'bottomLeft'
		}
	    }
        
        
	});
    });
    
    
}

Ischiaprenotazioni.lang = function(){
    $('div#lang_container').hide();
    
    $('li#lang_selector').click(function(){
	$('div#lang_container').slideToggle('swing');
    });
}

Ischiaprenotazioni.news = function(){
    $('div#news_cat').hide();
    
    $('span#news_cat_opener').click(function(){
	$('div#news_cat').slideToggle('swing');
	$('img', $(this)).toggle();
    });
}

Ischiaprenotazioni.filters = function(){
    $('div#filters').hide();

    $('div#filters input:checked').each(function(){
	    $(this).parent().siblings().addClass('selected_st');
    });

    $('div#filters_toggle').click(function(){
	$('div#filters').slideToggle('swing');
	$('img', $(this)).toggle();
    });

    $('div#filters :checkbox').click(function(){
	if($(this).is('input:checked')){
	    $(this).parent().siblings().addClass('selected_st');
	}else{
	    $(this).parent().siblings().removeClass('selected_st');
	}
    });
}

Ischiaprenotazioni.listingItems = function(){
    $('div.listing_item').each(function(){
	var currentListingItem = $(this);
	
	// nascondiamo tutti i div.listing_item_detail del listing_item corrente
	$('div.listing_item_detail', currentListingItem).hide();

	// bindiamo il toggle button del listing_item corrente
	$('div.listing_item_toggle', currentListingItem).click(function(){

	    // come contesto dobbiamo usare il currentListingItem: se usassimo $(this) verrebbero cercati i div.listing_item_detail figli di div.listing_item_toggle
	    $('div.listing_item_detail', currentListingItem).slideToggle('swing');
	    $('img', $(this)).toggle();
	});
    });
}


Ischiaprenotazioni.listingItems2 = function(){
    $('div.listing_item').each(function(){
	var currentListingItem = $(this);
	
	// nascondiamo tutti i div.listing_item_detail del listing_item corrente
	$('div.listing_item_detail2', currentListingItem).hide();

	// bindiamo il toggle button del listing_item corrente
	$('div.listing_item_toggle2', currentListingItem).click(function(){
	    // come contesto dobbiamo usare il currentListingItem: se usassimo $(this) verrebbero cercati i div.listing_item_detail figli di div.listing_item_toggle
	    $('div.listing_item_detail2', currentListingItem).slideToggle('swing');
	    $('img', $(this)).toggle();
	});
    });
}


Ischiaprenotazioni.listingItems3 = function(){
    $('div.listing_item_pep').each(function(){
	var currentListingItem = $(this);
	
	// nascondiamo tutti i div.listing_item_detail del listing_item corrente
	$('div.listing_item_detail_pep', currentListingItem).hide();

	// bindiamo il toggle button del listing_item corrente
	$('div.listing_item_toggle_pep', currentListingItem).click(function(){

	    // come contesto dobbiamo usare il currentListingItem: se usassimo $(this) verrebbero cercati i div.listing_item_detail figli di div.listing_item_toggle
	    $('div.listing_item_detail_pep', currentListingItem).slideToggle('swing');
	    $('img', $(this)).toggle();
	});
    });
}


Ischiaprenotazioni.commenti = function(){
    $('div#commenti').hide();

    $('div#commenti_opener').click(function(){
	$('div#commenti').slideToggle('swing');
	$('img', $(this)).toggle();
    });
}

Ischiaprenotazioni.scrolling = function(){
    $("#voto_goto").click(function() {
	$.scrollTo("div#commenti_view", 800);
	$('div#commenti_view').effect('bounce', {}, 400);
    });

    $("#offerte_goto").click(function() {
	$.scrollTo("div#offerte_view", 800);
	$('div#offerte_view').effect('bounce', {}, 400);
    });
}

Ischiaprenotazioni.offerta = function(){
    $("div.offerta:not(.processed)").addClass('processed').each(function() {
	$(this).hide();
    });

    $('div.offertacloser').each(function() {
	$(this).hide();
    });



    $(".offertaopener").each(function() {
	$(this).click(function() {
	    var id = $(this).attr('id');

	    var index = id.indexOf('_');
	    var offertaid = $(this).attr('id').substring(index + 1 , id.length );


	   // $("#offerta_" + offertaid).slideDown(400);
$("#offerta_" + offertaid).slideToggle('swing')
	    $("#offertacloser_" + offertaid).show();
	});
    });


    $(".offertacloser").click(function() {
	var id = $(this).attr('id');
	var index = id.indexOf('_');
	var offertaid = $(this).attr('id').substring(index + 1 , id.length );

	$("#offerta_" + offertaid).slideUp(400);
	$("#" + id).hide();
    });
    
}



