this.nav = function() {
	$("#nav a").css("display","none");
	$("#nav a").css("background-position","0 -69px");
	$("#nav li").css("cursor","pointer");
 	$("#nav li").hover(
      function(){
        $("a",this).fadeIn("fast");
      }, 
      function(){
        $("a",this).fadeOut("fast");
      }
    );	
};
this.slideshow = function(obj) {	
		//var obj = $("#templates");
		var s = $("li", obj).length;
		var w = obj.width(); 		
		var ts = s-1;
		var t = 0;
		$("ul", obj).css("width",s*w);
		$(obj).parent().append("<span class=\"prev\"><a href=\"javascript:void(0);\">Previous</a></span> <span class=\"next\"><a href=\"javascript:void(0);\">Next</a></span>");
		
		$(".prev a", obj.parent()).hide();
		$(".next a", obj.parent()).click(function(){		
			animate("next");
			if (t>=ts) $(this).fadeOut();
			$(".prev a", obj.parent()).fadeIn();
		});
		$(".prev a", obj.parent()).click(function(){		
			animate("prev");
			if (t<=0) $(this).fadeOut();
			$(".next a", obj.parent()).fadeIn();
		});	
		this.animate = function(dir){
			if(dir == "next"){
				t = (t>=ts) ? ts : t+1;	
			} else {
				t = (t<=0) ? 0 : t-1;
			};		
			p = (t*w*-1);		
			$("ul",obj).animate(
				{ marginLeft: p }, 
				900
			);	
		};
		animate("next");
		$(".prev a", obj.parent()).fadeIn();
};
this.preview = function() {
	if(document.body.id == "preview"){		
		$("body").each(function(){
			h = $(window).height();
			w = $(window).width();		
			$("body").append('<iframe width="'+ w +'" height="'+ (h-69) +'" src="http://templatica.com/previews/'+ template +'" id="previewTemplate" frameborder="0" scrolling="auto" marginheight="0" marginwidth="0"></iframe>');		
		});	
	}
};

this.pngfix = function() {
	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	if (jQuery.browser.msie && (ie55 || ie6)) {		
		$("*").each(function(){
			var bgIMG = $(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				$(this).css('background-image', 'none');
				$(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			};
		});
	};		
};

this.init = function() {
	pngfix();
	//nav();	
	$("#templates").each(function(){	
		slideshow($(this));	
	});		
	preview();
};

$(document).ready(function(){	
	init();
});
