var intervaler = null;
var running = false;
var has_ran = false;
var slideTimer = null;
var slideInProgress = false;

hideLoader = function() {
  $('#loader').hide();
}
showLoader = function() {
  $('#loader').show();
}

hideHomepageLoader = function() {
  $('#homepage-loader').hide();
}

function slideSwitch() {
    var $active = $('#rotator .active');
    if ( $active.length == 0 ) $active = $('#rotator li:last');

    var $next =  $active.next().length ? $active.next() : $('#rotator li:first');

    $active.addClass('last_active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2500, function() {
            $active.removeClass('active last_active').css({opacity: 0.0});
        });
}

function startSlideShow(){
  if(!slideInProgress && $('#rotator ul li').length >= 2)
  {    
    slideTimer = setInterval( "slideSwitch()", 6000 );
    slideInProgress = true;
  }
}

function stopSlideShow(){
  clearInterval(slideTimer);
  slideInProgress = false;
}

$(window).blur(function(){
  stopSlideShow();
}).focus(function(){
  startSlideShow();
});

$(document).ready(function() {		
	//Load the slideshow
	$('#loader').css('height', $('#wrapper').height() - 180 );
	$('#homepage-loader').css('height', $('#wrapper').height() - 180 );
});

$(window).load(function() {
  hideHomepageLoader();
});

$(window).load(function(){
	$('#rotator ul').show();
	startSlideShow();
});

$(document).ready(function(){
$('div.G1').galleryScroll({autoSlide:6000});
			
			
			$("a.gallery-group").fancybox({
				'titlePosition'	: 'inside'
			});
			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			$("#various1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
			$("#various2").fancybox();
			$("#various3").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			$("#various4").fancybox({
				'padding'			: 0,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
						   
	
	$( ".promotions" ).click(function() {
		$( ".uistateactive" ).css("display","block");
  		 $( "#footer-bg .slide" ).css("display","block");
		 $( ".promotions" ).css("display","none");
		   return false;
		 
 	});
	$( ".uistateactive" ).click(function() {
		 $( ".promotions" ).css("display","block");
		 $( ".uistateactive" ).css("display","none");
  		  return false;
 	});
	
	$( ".quick-room_search" ).click(function() {
		 $( ".promotions" ).css("display","block");
  		 $( "#footer-bg .slide" ).css("display","block");
		 $( ".uistateactive" ).css("display","none");
  		  return false;
 	});
	
	
	$( ".quick-room_search" ).click(function() {
		$( ".state-active" ).css("display","block");
  		 $( ".accordion-slide" ).css("top","34px");
		 $( ".quick-room_search" ).css("display","none");
			  return false;
 	});
	$( ".state-active" ).click(function() {
		 $( ".quick-room_search" ).css("display","block");
  		 $( ".accordion-slide" ).css("top","-500px");
		 $( ".state-active" ).css("display","none");
  		  return false;
 	});
 	
	$('ul.accordion3').accordion({	
	  active: false,
		autoHeight: false,
		header: ".opener",
		collapsible: true,
		event: "click",
		change: function(event, ui) {
		  $('.room-layout img').attr('src', ui.newContent.attr('rel'));
		  $('.room-layout a').attr('href', ui.newContent.attr('image'));
		  if (ui.newContent.attr('configuration') != undefined)
		    window.location.hash = "#" + ui.newContent.attr('configuration');
	    else window.location.hash = null;
	    var active = $("ul.accordion3").accordion("option", "active");
	    if (active === false) {	      
        //$('.room-layout img').attr('src', originalSrc);
        //$('.room-layout a').attr('href', originalHref);
	    }
    }
	});
	
	if (window.location.hash) {
	  $('ul.accordion3').accordion("activate", $('ul.accordion3').children().index($(window.location.hash)));
	}	else {
    $('ul.accordion3').accordion("activate", 0);
	}

});

$(function() {
	$( ".promotions" ).click(
		function() {
			$( ".uistateactive" ).animate({
				top:-236
			}, 1000 );
			$( "#footer-bg .slide" ).animate({
				height:200,
				top:-202
			}, 1000 );
			$( ".promotions" ).animate({
				top:0
			}, 1000 );
			
		},
		function() {
			$( ".uistateactive" ).animate({
				top:-236
			}, 1000 );
			$( ".promotions" ).animate({
				top:-236
			}, 1000 );
			$( "#footer-bg .slide" ).animate({
				height:200,
				top:-202
			}, 1000 );
			
		}

	);
	$( ".uistateactive" ).click(
		function() {
			$( "#footer-bg .slide" ).animate({
				height:200,
				top:-202
			}, 1000 );
			$( ".uistateactive" ).animate({
				top:-34
			}, 1000 );
			$( ".promotions" ).animate({
				top:-34
			}, 1000 );
		},
		function() {
			$( "#footer-bg .slide" ).animate({
				height:0,
				top:-1
			}, 1000 );
			$( ".promotions" ).animate({
				top:-34
			}, 1000 );
			$( ".uistateactive" ).animate({
				top:-34
			}, 1000 );
		}
	);
	$( ".quick-room_search" ).click(
		function() {
			$( "#footer-bg .slide" ).animate({
				height:200,
				top:-202
			}, 1000 );
			$( ".uistateactive" ).animate({
				top:-34
			}, 1000 );
			$( ".promotions" ).animate({
				top:-34
			}, 1000 );
		},
		function() {
			$( "#footer-bg .slide" ).animate({
				height:0,
				top:-1
			}, 1000 );
			$( ".promotions" ).animate({
				top:-34
			}, 1000 );
			$( ".uistateactive" ).animate({
				top:-34
			}, 1000 );
		}
	);
	$(".promotions-carousel li a").fancybox({
	  'width': 400,
    'height': 400,
    'enableEscapeButton' : true,
    'overlayShow' : true,
    'hideOnOverlayClick' : true,
     ajax: {
       type     : "POST",
       cache    : false,
       url      : "/components/profile/buyer/regbuyer1.php"
    }
  });
});



