var gallDelay = 5000; // gallery lightbox auto rotation delay
(function($){
	//Custume style select box
 	$.fn.extend({
 	customStyle : function(options) {
	  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
	  return this.each(function() {	  
			var currentSelected = $(this).find(':selected');
			$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
			var selectBoxSpan = $(this).next();
			var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$(this).height(selectBoxHeight).change(function(){				
			selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');			
		});			
	  });
	  }
	}
 });
})(jQuery);
$(function(){
	
	$('.styled').customStyle();	
});

jQuery(function(){
	
	//video gallery page
	var lilength=$("ul.thumbs li").length; 
	if(lilength <= 3)
	{
		$(".galprev").addClass("disableprev");
		$(".galnext").addClass("disablenext");
		
	}
	
	// main menu dropdown
	$("ul#nav li.active ul").addClass("hold");
	$("ul#nav li:not(ul#nav ul li)").hover(function()
	{
		if(!$(this).parent().hasClass("hold"))
			$(".hold").hide();
		
		$(this).addClass("active2");
		$("ul", $(this)).show();
	}, function()
	{
		$(this).removeClass("active2");
		$("ul", $(this)).hide();
		
		if($(this).parent().attr("id")=="nav")
			$(".hold").show();
	});
	
	//header image		
	$('#container .header').cycle({
		fx:     'fade',
		speed: 1000,
		timeout: 6000,
		next:".btnext",
		prev:".btprev",
		pager: '.banner-images-nav',
		before:onBefore,
		after:onAfter,
		pagerAnchorBuilder: function(idx, slide){
			$('.hd_controls_bullets').append(
				'<li>' +
				'<a id="' + idx + '" href="#">&nbsp;</a>' +
				'</li>'
			);
			return '<li><a href="#">&nbsp;</a></li>';
		}
	});
	function onAfter() { 
		$('.hd_controls_bullets li a').each(function(index) {
    		$('.hd_controls_bullets li a:eq(' + (index) + ')').addClass($('.banner-images-nav li a:eq(' + (index) + ')').attr('class'));
	  	});
	}
	function onBefore() { 
		$('.hd_controls_bullets li a').each(function(index) {
			$('.hd_controls_bullets li a:eq(' + (index) + ')').removeClass("activeSlide");
	  	});
	}	
	//Second cycle, even simpler
	$('.caption').cycle({
		fx:     'fade',
		speed: 1000,
		timeout: 6000,
		next:".btnext",
		prev:".btprev",
		pager: '.caption_pager',
		pagerAnchorBuilder: function(idx, slide){
			return '<li><a href="#">&nbsp;</a></li>';
		}
	});	
	//Hide all of the pagers except the master pager
	$('.caption_pager').hide();
	$('.banner-images-nav').hide();
	$(".hd_controls_bullets li a#0").addClass('activeSlide');
	$('.hd_controls_bullets li a').live('click', function(){
		$(this).addClass("activeSlide");
		$('.caption_pager li:eq(' + $(this).attr('id') + ') a').trigger('click');
		$('.banner-images-nav li:eq(' + $(this).attr('id') + ') a').trigger('click');
		$('.caption').cycle('pause');
		$('#container .header').cycle('pause');
		return false;
	});
	$('.btnext,.btprev').click(function(){
		$('.caption').cycle('pause');
		$('#container .header').cycle('pause');
	});
	
	// my aurora promo 
	$(".my_aurora_promo .events_items").cycle(
	{
		fx: "fade",
		speed: 500,
		timeout: 5000,		
		pager: ".aurora_promo_bullet",
		pagerAnchorBuilder: function(idx, slide)
		{
			return '<li><a href="#">&nbsp;</a></li>';
		}
	});
	
	$(".aurora_promo_bullet li").click(function(){
		$(".my_aurora_promo .events_items").cycle('pause');
	});
	
	// featured event promo
	$(".featured_event .events_items").cycle(
	{
		fx: "scrollHorz",
		speed: 500,
		timeout: 5000,		
		pager: ".featured_event_bullet",
		pagerAnchorBuilder: function(idx, slide)
		{
			return '<li><a href="#">&nbsp;</a></li>';
		}
	});
	
	$(".featured_event_bullet li").click(function(){
		$(".featured_event .events_items").cycle('pause');
	});
	
	// my aurora internal promo 
	$(".aurora_int_items").cycle(
	{
		fx: "fade",
		speed: 500,
		timeout: 5000,		
		pager: ".aurora_int_promo_bullet",
		pagerAnchorBuilder: function(idx, slide)
		{
			return '<li><a href="#">&nbsp;</a></li>';
		}
	});
	$(".aurora_int_promo_bullet li").click(function(){
		$(".aurora_int_items").cycle('pause');
	});
	
	// infobox promo
	$(".infobox_promo_img").cycle(
	{
		fx: "scrollHorz",
		speed: 500,
		timeout: 5000,		
		pager: ".infobox_promo_bullet",
		pagerAnchorBuilder: function(idx, slide)
		{
			return '<li><a href="#">&nbsp;</a></li>';
		}
	});
	
	// history promo 
	$(".history_promo .history_promo_img").cycle(
	{
		fx: "fade",
		speed: 500,
		timeout: 5000,	
		pager: ".history_promo_bullet",
		pagerAnchorBuilder: function(idx, slide)
		{
			return '<li><a href="#">&nbsp;</a></li>';
		}
	});
	
	// Event page promo 
	$(".event_page_promo .event_page_promo_img").cycle(
	{
		fx: "fade",
		speed: 500,
		timeout: 5000,	
		pager: ".event_page_promo_bullet",
		pagerAnchorBuilder: function(idx, slide)
		{
			return '<li><a href="#">&nbsp;</a></li>';
		}
	});
	
	// stories page
	$(".stories_int_items").cycle(
	{
		fx: "scrollHorz",
		speed: 500,
		timeout: 5000,		
		pager: ".stories_int_promo_bullet",
		pagerAnchorBuilder: function(idx, slide)
		{
			return '<li><a href="#">&nbsp;</a></li>';
		}
	});
	
	$(".stories_int_promo_bullet li").click(function(){
		$(".stories_int_items").cycle('pause');
	});
	
	// home page view more
	$('a.more').toggle(
		function(){
			$('.hp_more_content').slideDown()
			$(this).html("<a class='less' href='#' title='Read Less'>Read Less</a>");
			$(this).addClass("less");
			$(this).removeClass("more");
		},
		function(){
			$('.hp_more_content').slideUp()
			$(this).html("Read More");
			$(this).removeClass("less");
			$(this).addClass("more");
		}
	);
	
	// event calendar page
	$('.select_cat a.more').toggle(
		function(){
			$('.hide_cat').slideDown()
			$(this).html("<a class='less' href='#' title='select category'>select category</a>");
			$(this).addClass("less");
			$(this).removeClass("more");
		},
		function(){
			$('.hide_cat').slideUp()
			$(this).html("select category");
			$(this).removeClass("less");
			$(this).addClass("more");
		}
	);
	
	//print 
	$('.print_page a').css({'display':'inline'}).click(function(){
		window.print();
		return false;
	 });
	
	//View More Events
	$('.moreevents').click(	function(){
		
      if($('.moreevents').hasClass('morelist')) {
		$(this).removeClass('morelist');
        $('#ongoing_events_list').animate({height:58},500);
      } 
	  else { 
	   $(this).addClass('morelist');
       $('#ongoing_events_list').animate({height:268},500);
      }
  });

	//category search form
	$('#sub_cat_select').change(function() {
	  $("#cat_form").submit();
	});
	
	//Left panel search form submit
	$('#search_btn').click(function() {
	  $("#search_left_form").submit();
	});
	
	//Email Signup
	$("#email").click(function(){
		if (this.value == this.defaultValue) this.value = '';
	});
	$("#email").blur(function(){
		if ( $(this).val().length==0) {
			$(this).val(this.defaultValue);
		}
	});
	$('#frmemail .search_btn').click(function() {
		if(checkEmail(document.NDU0NDExMTc6LTE.email.value))
		{$("#frmemail").submit();}
	});
		
	//enter adress
	$(".add").click(function(){
		if (this.value == this.defaultValue) this.value = '';
	});
	$(".add").blur(function(){
		if ( $(this).val().length==0) {
		$(this).val(this.defaultValue);	}
	});	

	//form calendar
	$( ".datepicker-arrival").datepicker({
		showOn: "button",
		buttonImage: sitepath+"images/calendar.gif",
		buttonImageOnly: true,
		buttonText: 'Calendar',
		minDate:'0'
	});

	$( ".datepicker-departure").datepicker({
		showOn: "button",
		buttonImage: sitepath+"images/calendar.gif",
		buttonImageOnly: true,
		buttonText: 'Calendar',
		minDate:'0'
	});
	
	// photo gallery light box
	var gallTimer;
	  if($('a.group').length > 0) {
		$("a.group").fancybox({
		  transitionIn: 'fade',
		  transitionOut: 'fade',
		  speedIn: 600,
		  speedOut: 200,
		  overlayShow: true,
		  overlayOpacity: 0.6,
		  hideOnContentClick: true,
		  overlayColor: '#000',
		  titleShow: true,
		  titlePosition: 'over',
		  showNavArrows: true,
		  padding: 20,
		  titleFormat: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over"><span class="img_count">' + (currentIndex + 1) + ' of ' + currentArray.length +'</span> '+ (title.length ? ' &nbsp; ' + title : '') +' </span>';
				},
		  cyclic: true,
		  onComplete: function(){
			clearTimeout(gallTimer);
			gallTimer = setTimeout($.fancybox.next, gallDelay)
		  },
		  onClosed: function(){
			clearTimeout(gallTimer)
		  }
		});
	  }
	  if($('.items a.play').length > 0) {

		 $(".items a.play").fancybox({
			  'title'				: this.title,
			  'overlayShow': 		true,
			  'overlayOpacity': 	0.6,
			  'overlayColor': 		'#000',
			  'width'				: 640,
			  'height'				: 385,
			  'autoScale'			: false,
			  'transitionIn'		: 'none',
			  'transitionOut'		: 'none',
			  'titlePosition'		: 'inside',
			  'type'				: 'iframe'
		  });
	  }

//weather widget
	jQuery.simpleWeather({
		zipcode: '80012',
		unit: 'f',
		success: function(weather) {
			jQuery(".forcast h1").html(weather.temp+'&deg; '+weather.units.temp);
		},
		error: function(error) {
			jQuery(".temp").html('<p>'+error+'</p>');
		}
	});
	
	//pagination
	/*$('.results_details').each(function(i) {
        $(this).cycle({
			fx: "fade",
			speed: 500,
			timeout:0,
		    pager:  '.numeric' + i,   
			pagerAnchorBuilder:	function(index, slide){
					var inn=index+1;
					return '<a href="#">'+inn+'</a>';
				},
			next:".next",
			prev:".prev"        
        });
    });*/
	/*$(".results_details").cycle(
	{
		fx: "fade",
		speed: 200,
		timeout:0,
		pager: ".numeric",
		next:".next",
		prev:".prev"
		
	});*/
	if($('.results_details .det_pack_main .det_pack').length > 0) {
	  $('.results_details').pajinate({
		  items_per_page :10,
		  item_container_id : '.det_pack_main',
		  nav_panel_id : '.alt_page_navigation'
		  
		  
	  });
	}
	if($('.results_details .det_pack_main .det_pack').length < 1){
		$('.results_details .det_pack_main').append("<div class='det_pack'><h3>No Search result found for selected criteria.</h3></div>")
		}


});
