$(document).ready(function(){

	// UNIFORM 
	$("#bf  select").uniform();
	$("#bf").css("visibility","visible");

	$('#slider').nivoSlider({
		effect: 'random',
		animSpeed:300,
		pauseTime:5000
	});
	$('#slider').css('visibility','visible');
	
	/* PHOTOGALLERY */
	/*$("div.gallery").cycle({
		timeout: 3000
	});*/
	
	$('#accesscode').click(function() {
	  $('#accesscode span').css('display','none');
	});

	/* CENTRARE TOP SHADOW */
	var w_window = $(window).width();
	//alert(w_window);
	var left = (w_window-1000)/2;
	//alert(left);
	//$('#wrapper_topimage .top_shadow').css('left',left);


	/*Gallery nel default item*/
	jQuery(function($) {		
		$('.small_gallery_demo_unstyled').addClass('small_gallery_demo'); // adds new class name to maintain degradability		
		$('ul.small_gallery_demo').galleria({
			history   : true, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#main_image_small', // the containing selector for our main image
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				// fade in the image & caption
				if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
					image.css('display','none').fadeIn(1000);
				}
				caption.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Next image >>');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				);
			}
		});
	});
	/*Fine Gallery nel default item*/
	
	/* GALLERY CATEGORY */
	$("a[rel=photogallery]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'over'
	});

	/* BOX RELATED ITEMS */
	$('#item-slidebox_tag-2').cycle({
		fx:     'fade',
		speed:  'fast',
		timeout: 2000,
		next:   '#item-slide-next_tag-2',
		prev:   '#item-slide-prev_tag-2'
	});
	$('#item-slidebox_tag-3').cycle({
		fx:     'fade',
		speed:  'fast',
		timeout: 2500,
		next:   '#item-slide-next_tag-3',
		prev:   '#item-slide-prev_tag-3'
	});

	/* BOX OFFERS ITEMS */
	//$('#item-slidebox_tag').cycle({
	$('#item-slidebox_tag-1').cycle({
		fx:     'fade',
		speed:  'fast',
		timeout: 4000,
		next:   '#item-slide-next_tag-1',
		prev:   '#item-slide-prev_tag-1'
	});


	// Link_exchange pager
	$('#link_exchange_links .pager').find('a').live('click', function () {
		var that = $(this);
		$('#link_exchange_links_container').height($('#link_exchange_links_container').height()).addClass('loading');
		$('#link_exchange_links').fadeOut(200, function () {
			$(this).load(that.attr('href') + ' #link_exchange_links > *', function  () {
				$(this).fadeIn(200);
				$('#link_exchange_links_container').height('auto').removeClass('loading');
			});
		});
		return false;
	});

	// Guest comments pager
	$('#guestcomments .pager').find('a').live('click', function () {
		var that = $(this);
		$('#guestcomments-container').height($('#guestcomments-container').height()).addClass('loading');
		$('#guestcomments').fadeOut(200, function () {
			$(this).load(that.attr('href') + ' #guestcomments > *', function  () {
				$(this).fadeIn(200);
				$('#guestcomments-container').height('auto').removeClass('loading');
			});
		});
		return false;
	});
	
	
	
	/* ITEM ROOM */
	$('ul.menu_level_0 li.cat_2 ul.cat_2 li a').live('click', function () {
		var id_ele = $(this).attr('id');
		id_ele = id_ele.substring(9);
		
		id_ele = id_ele.replace("cat-tree-first","");
		id_ele = id_ele.replace("cat-tree-last","");
		//alert(id_ele);
		
		linked_page = $(this).attr('href') + ' .left-col';
		linked_minigallery = $(this).attr('href') + ' .minigallery-room > *';
		
		$('#wrapper_category_box .left-col').load(linked_page, function() {
		//	alert("a");
			
			$('#navbar ul.current li.level_1 a').each(function() {	
				$(this).removeClass('current');
			});
			$('#wrapper_category_box ul.item-slidebox-rooms li.item-room .title a').each(function() {
				$(this).removeClass('current');
			});
		
			$('#navbar ul.current a.cat_'+id_ele).addClass('current');
			// alert();
			$('#ele_item_'+id_ele+' .title a').addClass('current');
			
			$('.minigallery-room').load(linked_minigallery, function() {
				$('.small_gallery_demo_unstyled').addClass('small_gallery_demo'); // adds new class name to maintain degradability		
				$('ul.small_gallery_demo').galleria({
					history   : true, // activates the history object for bookmarking, back-button etc.
					clickNext : true, // helper for making the image clickable
					insert    : '#main_image_small', // the containing selector for our main image
					onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
						
						// fade in the image & caption
						if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
							image.css('display','none').fadeIn(1000);
						}
						caption.css('display','none').fadeIn(1000);
						
						// fetch the thumbnail container
						var _li = thumb.parents('li');
						
						// fade out inactive thumbnail
						_li.siblings().children('img.selected').fadeTo(500,0.3);
						
						// fade in active thumbnail
						thumb.fadeTo('fast',1).addClass('selected');
						
						// add a title for the clickable image
						image.attr('title','Next image >>');
					},
					onThumb : function(thumb) { // thumbnail effects goes here
						
						// fetch the thumbnail container
						var _li = thumb.parents('li');
						
						// if thumbnail is active, fade all the way.
						var _fadeTo = _li.is('.active') ? '1' : '0.3';
						
						// fade in the thumbnail when finnished loading
						thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
						
						// hover effects
						thumb.hover(
							function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
						);
					}
				});
			});
			
		});
		
		return false;
	});
	
	$('ul.cal_categories li a').live('click', function () {
		var id_ele = $(this).parents('.item-room').attr('id');
		id_ele = id_ele.substring(9);
		//alert(id_ele);
		
		linked_page = $(this).attr('href') + ' .left-col';
		linked_minigallery = $(this).attr('href') + ' .minigallery-room > *';
		
		$('#wrapper_category_box .left-col').load(linked_page, function() {
		//	alert("a");
			
			$('#navbar ul.current li.level_1 a').each(function() {	
				$(this).removeClass('current');
			});
			
			$('#wrapper_category_box ul.item-slidebox-rooms li.item-room .title a').each(function() {
				$(this).removeClass('current');
			});
		
			$('#navbar ul.current a.cat_'+id_ele).addClass('current');
			$('#ele_item_'+id_ele+' .title a').addClass('current');
			
			$('.minigallery-room').load(linked_minigallery, function() {
				$('.small_gallery_demo_unstyled').addClass('small_gallery_demo'); // adds new class name to maintain degradability		
				$('ul.small_gallery_demo').galleria({
					history   : true, // activates the history object for bookmarking, back-button etc.
					clickNext : true, // helper for making the image clickable
					insert    : '#main_image_small', // the containing selector for our main image
					onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
						
						// fade in the image & caption
						if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
							image.css('display','none').fadeIn(1000);
						}
						caption.css('display','none').fadeIn(1000);
						
						// fetch the thumbnail container
						var _li = thumb.parents('li');
						
						// fade out inactive thumbnail
						_li.siblings().children('img.selected').fadeTo(500,0.3);
						
						// fade in active thumbnail
						thumb.fadeTo('fast',1).addClass('selected');
						
						// add a title for the clickable image
						image.attr('title','Next image >>');
					},
					onThumb : function(thumb) { // thumbnail effects goes here
						
						// fetch the thumbnail container
						var _li = thumb.parents('li');
						
						// if thumbnail is active, fade all the way.
						var _fadeTo = _li.is('.active') ? '1' : '0.3';
						
						// fade in the thumbnail when finnished loading
						thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
						
						// hover effects
						thumb.hover(
							function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
						)
					}
				});
			});
			
		});
		
		//$('#wrapper_category_box .left-col').html('');
		return false;
	});
	
	
	
});
