	$( function() {

		$('a.gallery').mouseover(function() {
			$('#heroShot').attr('src', $(this).attr('rel'));
			$('#caption p.mb00').text($(this).attr('title'));
			$('#caption p:gt(0)').hide();
		})

		tipper();
				
//		$('a[href^=http]').attr("target", "_blank"); // Begins with http:// means external link, target blank page
//		$('a[href$=pdf]').attr("target", "_blank"); // Ends with pdf means external file, target blank page
	});

	this.tipper = function(){	
		section = document.body.className;
		sectionColour = "#d79124";
		
		xOffset = 20;
		yOffset = 20;
		tipWidth = 250;
		
		switch (section){
			case "s-home":
				sectionColour = "#d79124";
				break;
			case "s-interior_design":
				sectionColour = "#a888b5";
				break;
			case "s-renovations":
				sectionColour = "#62b0bc";
				break;
			case "s-commercial_design":
				sectionColour = "#4c86c7";
				break;
			case "s-project_management":
				sectionColour = "#c4393b";
				break;
			case "s-cabinet_making":
				sectionColour = "#b16a52";
				break;
			case "s-handyman_service":
				sectionColour = "#511478";
				break;
			case "s-gallery":
				sectionColour = "#8f4e83";
				break;
			case "s-pricing":
				sectionColour = "#8193c6";
				break;
			case "s-testimonials":
				sectionColour = "#b8967c";
				break;
			case "s-contact_us":
				sectionColour = "#809d6c";
				break;
		}
		
		$('.tipped').hover(
				function (e) {
					x = e.pageX + xOffset;
					y = e.pageY + yOffset;
					x = (x + tipWidth > $(document).scrollLeft() + $(window).width()) ? x - tipWidth - (xOffset * 2) : x;
					y = (y + $('#toolTipWrapper').outerHeight() > $(document).scrollTop() + $(window).height()) ? $(document).scrollTop() + $(window).height() - $('#toolTipWrapper').outerHeight() - 10 : y
	
					this.tip = this.title;
					this.title = "";
					$("body").append(unescape('%3Cdiv id="toolTipWrapper"%3E' + this.tip + '%3C/div%3E'));
					$('#toolTipWrapper')
						.css({
							'background-color': sectionColour,
							'top': y + "px",
							'left': x + "px",
							'position': 'absolute',
							'width': tipWidth,
							'padding': '5px 10px',
							'color': '#fff',
							'border': '1px solid #fff',
							'-moz-border-radius': '0 10px',
							'-webkit-border-radius': '0 10px',
							'border-radius': '0 10px',
							'font-size': '1.1em'
						})
						.fadeIn("fast");
				},
				function () {
					this.title = this.tip;
					$('#toolTipWrapper').fadeOut(100);
					$('#toolTipWrapper').remove();
				}
			).click(function () {
				this.css({'cursor' : 'pointer'});
			});
	
		$(".tipped").mousemove(function (e) {
			x = e.pageX + xOffset;
			y = e.pageY + yOffset;
			x = (x + tipWidth > $(document).scrollLeft() + $(window).width()) ? x - tipWidth - (xOffset * 2) : x;
			y = (y + $('#toolTipWrapper').outerHeight() > $(document).scrollTop() + $(window).height()) ? $(document).scrollTop() + $(window).height() - $('#toolTipWrapper').outerHeight() - 10 : y
			$("#toolTipWrapper").css({
				"top": y + "px",
				'left': x + "px"
			});
		});
		
	};

