// JavaScript Document
var j = 0;
var quotes;
var counter = 1;
var delay;
var cat;


jQuery(document).ready(function($){
						   
	if (document.getElementById("hero")) {
		jQuery("div.quote").hide();	
		quotes = new Array();
		quotes = jQuery("div.quote");
		selectQuote();
	}
	
	if (document.getElementById("gdThumbs")) {
		jQuery("a.gdthumb").each(function(i){
			jQuery(this).click( function() {
				//Catch click and load into main panel
				cat = jQuery(this).attr('href'); 
				loadCategoryImages(cat);
				return false;
			  });
		});
	}
	
	if ($("#DesignTips")) {
	//get search term from querystring
	var qs = window.location.search;
	var selector = qs.split("=");
	//selector[1] == "utm_term") {
	$('#' + selector[1]).css('font-weight','bold');
}
});

function selectQuote(jp) {
	//alert(j);
	if (j != 0 || counter ==2) {
		jQuery(quotes[j]).animate({
	   opacity: 'hide'
	 }, 1000);
	}
	
	if (j == quotes.length-1) {
		j = 0;
		counter = 1;
	}
	
	if (j != 0 || counter>1) {j++;}
	

	if (quotes[j] == "") {
		jQuery(quotes[1]).animate({
	   opacity: 'show'
	 }, 1000);
	}
	else {
		jQuery(quotes[j]).animate({
	   opacity: 'show'
	 }, 1000);
	}
	counter ++;
	delay = setTimeout("selectQuote(" + j + ")",5000)
}

function loadCategoryImages(category) {
			clearTimeout(delay);
			var processor = "imageloader.php";
			jQuery.ajax({
			   type: "POST",
			   url: processor,
			  data: "directory=" + category,
			  
			   timeout: 10000,
				error: function(msg){
					jQuery("#gdMain").html('<p>error</p>'); 
				},
			   success: function(msg){
				 jQuery("#gdMain").html(msg); 
				 jQuery("div.quote").hide();	
				quotes = new Array();
				quotes = jQuery("div.quote");
				j=0;
				counter=1;
				 selectQuote(0);
			   }
			 });
			return false;
}
