/* -----------------------------------------------
BASE
----------------------------------------------- */
Cufon.replace('p');

$(function() {
	Setup.init();
	Background.init();
	YouTube.init();
	Images.init();
});

/*	Setup
----------------------------------------------- */

var Setup = {	
	Body: null,
	init: function() {
		var cc = this;
		cc.Body = $("body");
		$(window).resize(function(){
			cc.render();
		});
		cc.render();
	},
	render: function() {
		var cc = this;
		if($(window).height()<700) {
			cc.Body.addClass('lowres');
		}
		else {
			cc.Body.removeClass('lowres');
		}
	}
};

var Background = {
	Body: null,
	Colours: null,
	init: function() {
		var cc = this;
		cc.Body = $("body");
		
		cc.Colours = new Array();
		cc.Colours[0] = "#f9c8dd";
		cc.Colours[1] = "#cce5f2";
		cc.Colours[2] = "#dbedd6";
		cc.Colours[3] = "#fff5c9";
		cc.Colours[4] = "#f6e6c2";
		cc.Colours[5] = "#fff43e";
		cc.Colours[6] = "#6cf3d2";
		cc.Colours[7] = "#d3ee32";
		cc.Colours[8] = "#ff6fbe";
		cc.Colours[9] = "#7ff36c";
		cc.Colours[10] = "#dda2f4";
		
		cc.Current = Math.floor(Math.random()*11);
		
		cc.render();
		
	},
	render: function() {
		var cc = this;
		cc.Body.colorBlend([{colorList:["current",cc.Colours[cc.Current]], cycles: 1, strobe: false}]);
		if(cc.Current>=10) {
			cc.Current=0;
		}
		else {
			cc.Current ++;
		}
		$.doTimeout(30000, function(){
			cc.render();
		});
	}
};

var Images = {
	init: function() {
		var cc = this;
		$("a[href*=.jpg]").fancybox({
			'easingIn'      : 'easeOutBack',
			'easingOut'     : 'easeInBack',
			'overlayShow'	: false,
			'titlePosition' : 'inside'
		});
	}
}

var YouTube = {
	Triggers: null,
	init: function() {
		var cc = this;
		cc.Triggers = $('a[href*=youtube.com]');
		cc.events();
	},
	events: function() {
		var cc = this;
		cc.Triggers.click(function() {
			var id = $(this).attr('href').replace(/^[^v]+v.(.{11}).*/,"$1");
			var data = '<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/'+id+'?autoplay=1" frameborder="0"></iframe>';
			$.fancybox(data, {
				'autoDimensions' : true,
				'scrolling' : 'no',
				'easingIn'  : 'easeOutBack',
				'easingOut'  : 'easeInBack',
				'overlayShow'	: false
			});	
			return false;
		});
	}
};
