var heroImages = new Array();

$(function() {	
	if($("#photo-gallery").length)
	{
		var $gallery = $("#photo-gallery");
		var numSlides = $(".slides img", $gallery).length;
		$(".slides", $gallery).cycle(
	    {
	    	fx: "fade",
	    	speed: "800",
	    	timeout: "4000",
	    	next: $("a.btn_next"),
	    	prev: $("a.btn_prev"),
	    	after: function(cs, ns, opts)
			{
			    $("p.caption").text($(ns).attr("rel"));
			    $("p.count").text("Photo " + (opts.currSlide + 1) + " of " + numSlides);
			}
	    });

	    $("a.btn_pause").click(function()
	    {
	    	if ($(this).data("paused") != true)
	    	{
	    		$(".slides").cycle("pause");
	    		$(this).data("paused", true);
				$(this).addClass("paused");
	    	}
	    	else
	    	{
	    		$(".slides").cycle("resume");
	    		$(this).data("paused", false);
				$(this).removeClass("paused");
	    	}
	    	return false;
	    });
	}
	
	$("#promo-banners .banners").cycle(
	{
		fx: 'scrollRight',
		speed: 800,
		timeout: 8000,
		pager: "#promo-banners .pager",
		cleartypeNoBg: true
	});
	
	var feed = new google.feeds.Feed("http://weather.yahooapis.com/forecastrss?w=150215");
	feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
	feed.load(function(result){
		if (!result.error) {
			var items = result.xmlDocument.getElementsByTagName("item");
			 for (var i = 0; i < items.length; i++) {
				 var weatherElement = google.feeds.getElementsByTagNameNS(items[i], "http://xml.weather.yahoo.com/ns/rss/1.0", "condition")[0];
			     $(".weather p.temp span").html($(weatherElement).attr("temp"));
			     $(".weather span.icon img").attr("src",'/extension/cdev_base/design/cdev_base/images/weathericons/'+$(weatherElement).attr("code")+".png")
			     
			     var forecastElement = google.feeds.getElementsByTagNameNS(items[i], "http://xml.weather.yahoo.com/ns/rss/1.0", "forecast")[1];
			     $(".weather p.range span.l").html($(forecastElement).attr("low"));
			     $(".weather p.range span.h").html($(forecastElement).attr("high"));
			 }			
		}
	});
	
	/*$("body#index #masthead").oneTime("0s", "hide", function() {
		$("#masthead").animate({"height": "25px"}, 500, function(){$(".inner", this).hide();});
		$("#masthead").bind("mouseclick",function(){
			$("body#index #masthead").stopTime("hide");
			$(".inner", this).show()
			$("#masthead").animate({"height": "134px"}, 400)
		}).bind("mouseleave",function(){
			$("body#index #masthead").oneTime("3s", "hide", function() {
				$("#masthead").animate({"height": "25px"}, 400, function(){$(".inner", this).hide();})
			});
		});
	});*/
	
	$("body#index #masthead .inner").hide();
	$("body#index #masthead").css({"height":"25px"});
	$("#masthead").bind("click",function(){
		$(".inner", this).show()
		$("#masthead").animate({"height": "134px"}, 400)
	}).bind("mouseleave",function(){
		$("#masthead").animate({"height": "25px"}, 400, function(){$(".inner", this).hide();})
	});
	
	$("form.validated").validate();
 	
  	if(heroImages.length >= 1){
  		$('<div style="background-image: url('+heroImages[0]+');" > <img style="width:1300px; height:425px; display:none;" src="'+heroImages[0]+'" /></div>').appendTo("#hero_graphic #cycle_me");
  		heroImages.shift();
  	}
  	
	$("#hero_graphic #cycle_me").cycle({
		fx: "fade",
		speed: 1600,
		timeout: 8000,
		before: function(curr, next, opts){
			if (!opts.addSlide) 
				return;
		
			$idx = $('#hero_graphic #cycle_me div').index(next);
			if ($idx > heroImages.length) {
	            opts.addSlide = null;
	            return; 
	        }
	       
			opts.addSlide('<div style="background-image: url('+heroImages[($idx-1)]+');" > <img style="width:1300px; height:425px; display:none;" src="'+heroImages[($idx-1)]+'" /></div>');
		}
	});	
	
});