/**
 * @author 			Andrew Mayhew
 * @date			2009-09-13 13:45:00
 * @name			home.js
 * @description		Contains js for all home page specific scripts
 */

/**
 * @description		Sets up the photo display on the home page using jQuery, Raphael JS and Cufon
 * 
 * @param {Object} function(
 */
var switchOnPolaroid = true;

$(document).ready(function() {

	if (switchOnPolaroid) {

		$(function(){
		
			var src = $("#band")[0].src;
			var text = $("#pPhotoInfo").html();
			var linkText = $("#pPhotoLink a").html();
			var link = $("#pPhotoLink a").attr("href");
			
			$("#holder").html("");
			
			var paper = Raphael("holder", 590, 520);
			var b = paper.image("/public/images/layout/bk-photo-tilt.png", 31, 30, 547, 466);
			
			var c = paper.image(src, 64, 70, 478, 356);
			c.rotate(5.1);
			
			if (jQuery.browser.msie) {
			
				var t = paper.text(50, 425, text).attr({
					"fill": "#000",
					"font-size": "14px",
					"text-anchor": "start"
				});
				t.rotate(5.1);
				
				var r = paper.rect(410, 450, 120, 25, 0).attr({
					"stroke": "#fff",
					"fill": "#fff",
					"fill-opacity": "0"
				});
				r.rotate(5.1);
				
				$(r.node).mouseover(function(){
					r.node.style.cursor = "pointer";
				});
				$(r.node).click(function(){
					location.href = link;
				});
				
				var l = paper.text(425, 459, linkText).attr({
					"fill": "#972020",
					"font-size": "14px",
					"text-anchor": "start"
				});
				l.rotate(5.1);
				
			}
			else {
			
				var t = paper.print(50, 440, text, paper.getFont("arial-cufon", 0), 14);
				var textLoop = 0;
				
				for (textLoop = 0; textLoop < text.length; textLoop++) {
				
					var y = textLoop;
					
					if (y != 0) 
						y = textLoop / 1.5;
					
					if (t[textLoop] != null) {
						t[textLoop].translate(0, y);
						t[textLoop].rotate(5.1);
					}
				}
				
				// Target for clicking to view more photos
				var r = paper.rect(410, 450, 120, 25, 0).attr({
					"stroke": "#fff",
					"fill": "#fff",
					"fill-opacity": "0"
				});
				r.rotate(5.1);
				
				$(r.node).mouseover(function(){
					r.node.style.cursor = "pointer";
				});
				$(r.node).click(function(){
					location.href = link;
				});
				
				// More Photos link text
				var l = paper.print(425, 473, linkText, paper.getFont("arial-cufon", 0), 14).attr({
					"fill": "#972020"
				});
				var textLoop = 0;
				
				for (textLoop = 0; textLoop < linkText.length; textLoop++) {
				
					var y = textLoop;
					
					if (y != 0) 
						y = textLoop / 1.5;
					
					if (l[textLoop] != null) {
						l[textLoop].translate(0, y);
						l[textLoop].rotate(5.1);
					}
					
				}
			}
			
		});
	}

});
