sson = {

	init : function () { 
		// no lightbox or iphoneflip for ie6
		// but, they get an updatebrowser-alert!
		if (jQuery.browser.msie) {
  			if(parseInt(jQuery.browser.version) > 6) {
				this.iphoneFlip();
				this.domAction();
			}
		}else{
			this.iphoneFlip();
			this.domAction();
		}

		this.homepageFlip();
		this.pngalize();
		this.pngfix();
		this.ecom();
		this.productpageFlip();
		if (jQuery.browser.msie) {
  			if(parseInt(jQuery.browser.version) > 6) {
      			this.lightbox();	
  			}else{
  				this.alertIe6();
  			}
		}else{
			this.lightbox();
		}
		
	},

	domAction : function () {
		$("body").addClass("js");	
		//$("#blog").hide();
		$("#blog-btn a").click(function() {
			$("#blog").slideToggle(400);
			return false;		
		});
		$(".newsContainer").show()
	},
	
	pngfix : function () {
		$(document).pngFix();	
	},
	
	alertIe6 : function () {
		$("#pageHolder").after('<div id="alertie6">You\'re using a really old web browser. Updating it to <a href="http://getfirefox.com">Firefox</a>, <a href="http://www.apple.com/safari">Safari</a>, <a href="http://www.google.com/chrome/">Chrome</a> or even a new <a href="http://www.microsoft.com/windows/products/winfamily/ie/default.mspx">Internet Explorer</a> will make your web experience quicker, safer and more visually appealing. On all websites.</div>');
	},
	
	pngalize : function () {
		$("#list-pages .page_item a").each(function(){
			$(this).html('<img src="/fonts/futura/11/000000/320/'+decodeURI($(this).html().toUpperCase())+'.png" alt="'+$(this).html()+'"/>');
		});
			$("h2").each(function(){
			$(this).html('<img src="/fonts/futura/16/000000/320/'+decodeURI($(this).html().toUpperCase())+'.png" alt="'+$(this).html()+'"/>');
		});
	},

	homepageFlip : function () {
		if($("#front-pics").length>0){
			$('#front-pic-no-js').addClass("hide");	
			$('#front-pics').removeClass("hide");
				$('#front-pics').cycle({
	    		fx:     'fade',
	    		sync:    1,
				timeout: 3000,
				speed: 	 550
			});
		}
	},

	ecom : function () {
		$(".btnBuy").removeClass("hide");
		$(".btnBuy").click(function() {
			buyItem=$("#"+this.id).children("span").html();
			$.post('/wp-content/themes/sson/feeds/btnBuy.php', { buy: buyItem}, sson.showBasket);
			$(this).find("img").attr({src: "/wp-content/themes/sson/img/adding.gif"});
			var oldid=this; //hackathon 2009
			var delay = function() {
				sson.restoreBuybtn(oldid);
			};
			setTimeout(delay, 3500);
			return false;
		});	
		$.post('/wp-content/themes/sson/feeds/btnBuy.php', { show: 0}, sson.showBasket);
	},
	
	showBasket : function (res) {	
		$("#basketContainer").html(res);
		if ($("#basketContainer").hasClass("hasItems")) {
			$("a#checkout").show();
		}
	},
	
	restoreBuybtn : function (cbid) {
		$(cbid).find("img").attr({src: "/wp-content/themes/sson/img/add.gif"})		
	},
	
	productpageFlip : function () {
		$(".entry-main-image-thumb").click(function() {
			clickedId="#"+this.id;
			$("#entry-main-image").fadeOut(250,function(){
				$("#entry-main-image").attr("src", $(clickedId+" .full-path").text()).fadeIn(1300);
			});
		});
	},
	
	lightbox : function () {
		$('.lightbox').lightbox({
			fileLoadingImage: '/wp-content/themes/sson/img/loading.gif',
			fileBottomNavCloseImage: '/wp-content/themes/sson/img/closelabel.gif'
		});
	},
	
	iphoneFlip : function () {
		$("#pageLoader").removeClass("hide");
		if($("#iphone-flip").length>0){
			$("#pageHolder").addClass("hide");
			$.preload( '#iphone-flip img', {
				onFinish: sson.runFlip,
				threshold: 2
			});
		}
	},
	
	runFlip : function () {
		$("#pageLoader").addClass("hide");
		$("#iphone-flip").removeClass("hide");
		$('#iphone-flip').cycle({
	    	fx:     'curtainX',
	    	sync:    1,
			timeout: 500,
			speed: 	 100,
			nowrap:  1
	    });
		setTimeout(sson.restoreSiteFront, 2000);	
	},
	
	restoreSiteFront : function () {
		$(document.body).fadeOut(500,function (){
			$("#iphone-flip").hide();
			$("#pageHolder").removeClass("hide");
			$(document.body).fadeIn();	
		});		
		
		
	}
	
}

$(document).ready(function() {
	sson.init();
});