var priceimg_url = '';
var priceimg_hover_url = '';

var fbLikeCode = '';

// timeouts per slide (in seconds) 
var timeouts = [0,-0.5,2,0]; 

function calculateTimeout(currElement, nextElement, opts, isForward) { 
	var index = opts.currSlide; 
	return (timeouts[index] + 6) * 1000; 
}

$(document).ready(function() {
	$('#welcome_block1').cycle({
		fx:			'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		pause:		1,
		timeoutFn:	calculateTimeout,
		speed:		1500
		});
	
	var pageLng = $('meta[http-equiv=language]').attr("content");
	
	if (pageLng == null) {
		var textpart = '';
		var i = 0;
		textpart = $('#pageinfo p:first-child').text();
		i = textpart.indexOf(':');
		textpart  = textpart.substring(0,i).toLowerCase();
		
		if (textpart == 'updated') {
			pageLng = 'en';
		} else {
			pageLng = 'de';
		}
	}
	
	switch (pageLng) {
		case 'en':
			priceimg_url = '/images/prices13_s_e.png';
			fbLikeCode = "<iframe src='http://www.facebook.com/plugins/like.php?locale=en_GB&href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FInstant-Sleep-Backpackerhostel%2F114517015253077&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=21' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:120px; height:21px;' allowTransparency='true'></iframe>";
			break;
		case 'de':
			priceimg_url = '/images/prices13_s_d.png';
			fbLikeCode = "<iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FInstant-Sleep-Backpackerhostel%2F114517015253077&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=21' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:120px; height:21px;' allowTransparency='true'></iframe>";
			break;
	}
	priceimg_hover_url = priceimg_url.substr(0,priceimg_url.length-4) + '_hover.png';
	
	
	$('#img_prices').mouseenter(function() { 
		$('#img_prices').attr('src', priceimg_hover_url);
	} );
	
	$('#img_prices').mouseleave(function() { 
		$('#img_prices').attr('src', priceimg_url);
	} );
	
	$("#link_show_fb_like").attr("href","#");
	
	$('#fb_show_like_button').mouseenter(function() {
		$('#fb_like_info').slideDown(100);
		$('#fb_show_like_button').css('border-color','#000000');
	} );
	
	$('#fb_show_like_button').mouseleave(function() {
		$('#fb_like_info').delay(800).slideUp(800);
		$('#fb_show_like_button').css('border-color','#aaaaaa');
	} );
	
	$('#link_show_fb_like').click(function() {
		$('#facebook_like').empty().append(fbLikeCode);
	} );
});
