
$(function() {

	//Scrollable Client Landing Page
	
	$("div.scrollable").prepend("<a class='prev'></a>"); 	
	$("div.scrollable").append("<a class='next'></a>");	
	$("div.scrollable").prepend("<div class='navi'></div>"); 	
	
	$("div.items").css({'height' : '214px', 'width' : '528px', 'float' : 'left'});

	// add the 'item' DIV wrapper to group <a> links in groups of two
	
	$(".items a:nth-child(odd)").each(function(){
    	var $this = $(this);
    	$this.add( $this.next() ).wrapAll("<div class='item'></div>");
	});
	
	//Main Scroller Event
	
	$("div.double").scrollable({				   
		clickable:false,
		onSeek: function() {
		$("#info").text("current index: " + this.getStatus().index);
		}
	});
	

	$("#trigger").click(function(event) { 
		event.preventDefault();
		$("#subscribe form").slideToggle() 
	});
	
	$("#trigger").toggle(
		function() {
			$("#subscribe").css({backgroundColor:"#000000"});
			$(this).css("background-image", "url(/images/minus.png)"); 
		},
		function() {
			$("#subscribe").css({backgroundColor:""});
			$(this).css("background-image", "url(/images/plus.png)"); 
		}
	);
	
	
	//Make RSS icon clickable with RSS link
	
	$("li.rss").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});
	$("li.rss").css("cursor","pointer");
	
	//Add <em> tags to news listing date text nodes

	$("span.date").each(function(){
   	var date = $(this);
    date.html( date.text().replace(/(^\w+)/,'<em>$1</em>') );
  	});
	
	//removes strong tags from inserted page content
	$("#mainContent h4 strong").css({fontWeight:"normal"});
	
	//Add DIV Markup to the Signup form to solve problem with checkboxes
	$("label[for='listsubscription9']").each(function(){
    var $this = $(this);
    $this
       .add($this.next())
       .add($this.next().next())
	   .add($this.next().next().next())
	   .add($this.next().next().next().next())
	   .add($this.next().next().next().next().next())
       .wrapAll("<div class='options'></div>");
	});
	 
	//open in new window title if rel="external"
	$("a[rel='external']").attr({title: "View (Opens in New Window)"});
	//open in new window if rel="external"
	$("a[rel='external']").click(function(){
    	window.open(this.href);
    	return false;
    });
	
	
	//Add Thanks Message Link (before loading facebox)
	$("#thanks-message").before("<a id='thanksPopup' rel='facebox' href='#thanks-message'></a>");
	
	$("div.error").attr("id", "error-message");
	$("#error-message").before("<a id='errorPopup' rel='facebox' href='#error-message'></a>");

	//Load Facebook Popup
	$("a[rel*=facebox]").facebox() 
	//autoclick to load form thanks message into a facebox + Hide thankyou meesage in the #subscribe DIV
	 
	//auto trigger thanks message popup
	$("#thanksPopup").click(); 
	$("#subscribe #thanks-message").css("display", "none");
	
	//auto trigger thanks message popup
	$("#errorPopup").click();
	$("#subscribe #error-message").css("display", "none"); 
	
	//If form error exists  keep the subscribe form open
	if ( $("#error-message").length > 0 ) {
	$("#subscribe form").css("display", "block");
	}
	
	//Faded Rollover Technique on MainNav	
    generateSprites(".nav", "current-", false, 500, "fade");
	
});





