jQuery(function(){
	var imgurl = "http://gacaribbean.com/wp-content/featured/";
	jQuery('#slider-nav li a').click(function(){
		if(jQuery(this).attr("id") != jQuery("#slider-more").attr("class")){
			var imgfadein = 600;
			var morefadein = 400;
			var postid = jQuery(this).attr("id");
			var main = jQuery('#slider-main');
			var more = jQuery('#slider-more');
			main.css({"background-image":""}).addClass("loading");
			more.hide();
			more.removeClass();
			jQuery.ajax({
				type: "GET",
				dataType: "xml",
				data: "postid="+postid+"&sid="+Math.random(),
				url: siteurl+"/slider.php",
				success: function(xml){
					jQuery(xml).find("post").each(function(){
						var pname = jQuery(this).find("name").text();
						var purl = jQuery(this).find("url").text();
						var pcontent = jQuery(this).find("desc").text();
						var pimg = jQuery(this).find("image").text();
						var pid = jQuery(this).find("id").text();
						newimage = "url("+imgurl+pimg+")";
						var loadImg = new Image();
						jQuery(loadImg).load(function(){
							main.removeClass("loading").hide();
							main.css({"background-image":newimage});
							more.find("h5").html(pname);
							more.find("span").html(pcontent);
							more.find("a").attr("href", purl);
							more.addClass("post-"+pid);
							
							more.fadeIn( morefadein );
							main.fadeIn( imgfadein );
						}).attr("src", imgurl+pimg);
						
					});
				},
				error:function (xhr, ajaxOptions, thrownError){
					main.html('<p class="ajaxmsg">xhr: '+xhr.status+'<br/>error: '+thrownError+'</p>').removeClass();
				}
			});
		}
		return false;
	});
});