/* Author: 

*/
/* inline labels */
$(document).ready(function() {
	$('input[title], textarea[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));	
		}
		
		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').addClass('focused');	
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');	
			}
		});
	});
});

/* CONTACT ICONS */
var ctIconGradUp = "108-#474747-#b2b2b2";
var ctIconGradOver = "108-#ce163f-#f22553";

var ctIconEmPath = "M19.662,22.8c-0.027-0.014-0.054-0.022-0.079-0.033c-0.01-0.005-0.019-0.008-0.027-0.015c-0.023-0.011-0.047-0.022-0.069-0.038c-0.007-0.003-0.017-0.009-0.022-0.012c-0.023-0.017-0.046-0.03-0.069-0.051l-1.426-1.095c-0.057,0.074-0.124,0.135-0.2,0.188l-8.341,5.838H30.57l-8.342-5.838c-0.075-0.054-0.144-0.114-0.197-0.188l-1.426,1.095c-0.023,0.021-0.048,0.034-0.071,0.051c-0.006,0.003-0.015,0.009-0.022,0.012c-0.022,0.016-0.045,0.027-0.069,0.038c-0.009,0.007-0.017,0.01-0.026,0.015c-0.027,0.011-0.053,0.02-0.079,0.033c-0.005,0-0.009,0.002-0.015,0.002c-0.033,0.016-0.064,0.022-0.099,0.032c-0.006,0-0.01,0-0.013,0c-0.031,0.008-0.06,0.014-0.087,0.016c-0.008,0.004-0.015,0.004-0.022,0.004c-0.034,0.003-0.067,0.003-0.1,0.003c0,0,0,0-0.002,0c-0.031,0-0.067,0-0.1-0.003c-0.007,0-0.014,0-0.021-0.004c-0.029-0.002-0.059-0.008-0.086-0.016c-0.005,0-0.011,0-0.015,0c-0.033-0.01-0.066-0.017-0.101-0.032C19.669,22.802,19.667,22.8,19.662,22.8z M34.001,11.835v16.33c0,0.644-0.525,1.168-1.168,1.168H7.165C6.523,29.333,6,28.809,6,28.165v-16.33c0-0.643,0.522-1.168,1.164-1.168h25.668C33.476,10.667,34.001,11.192,34.001,11.835z M32.251,26.338V13.696l-8.607,6.617L32.251,26.338z M20,20.615l10.657-8.199H9.341L20,20.615z M7.75,26.338l8.604-6.025L7.75,13.696V26.338z";

var ctIconPhPath = "M31.996,9.463c-0.055-0.368-0.085-0.762-0.477-0.925c-0.272-0.054-0.436-0.116-0.685,0.046c0,0.112-0.471,0.533-0.54,0.619c-0.258,0.313-0.516,0.626-0.773,0.939c-0.49,0.595-0.979,1.19-1.469,1.785c-0.033-0.228-0.071-0.455-0.105-0.682c0.003-0.012-0.004-0.114-0.081-0.237c-0.141-0.484-1.213-0.757-1.579-0.94c-1.244-0.471-2.731-0.96-3.922-1.158c-0.573-0.104-1.299-0.296-1.791,0.097c-0.5,0.607-1.021,1.202-1.5,1.826c-0.821,1.057-1.438,2.251-2.088,3.417c-1.052,1.877-2.404,3.478-3.766,5.131c-1.216,1.477-2.336,3.015-3.902,4.141c-0.479,0.345-1.315,0.688-1.315,1.38c-0.056,0.748,0.271,1.832,0.394,2.622c0.084,0.536,0.027,1.522,0.45,1.944c0.983,0.937,2.831,1.346,4.104,1.64c0.585,0.161,1.184,0.308,1.787,0.383c0.949,0.106,1.122,0.004,1.693-0.69c0.942-1.146,1.883-2.291,2.826-3.435c2.996-3.639,6-7.272,8.981-10.921c0-0.012,0.062-0.087,0.073-0.099c0.147-0.243,0.222-0.417,0.258-0.715c0.01-0.064,0.014-0.13,0.015-0.195c-0.028-0.689-0.415-1.32,0.065-1.902c0.343-0.414,0.684-0.829,1.024-1.244C30.445,11.348,31.231,10.402,31.996,9.463 M19.285,10.662c-0.001,0-0.002,0-0.003,0l0,0C19.281,10.662,19.284,10.662,19.285,10.662 M16.061,31.227C16.061,31.229,16.061,31.229,16.061,31.227 M16.061,31.226C16.061,31.224,16.061,31.224,16.061,31.226 M31.909,9.454c-1.189,1.445-2.378,2.891-3.567,4.336C29.531,12.345,30.72,10.898,31.909,9.454 M28.342,13.791c1.189-1.445,2.378-2.891,3.567-4.336C30.72,10.898,29.531,12.345,28.342,13.791 M19.366,10.656C19.366,10.656,19.366,10.656,19.366,10.656L19.366,10.656C19.365,10.656,19.365,10.656,19.366,10.656 M16.061,31.229C16.061,31.232,16.061,31.232,16.061,31.229 M16.061,31.233C16.061,31.234,16.061,31.234,16.061,31.233 M16.061,31.236L16.061,31.236L16.061,31.236L16.061,31.236L16.061,31.236 M19.281,10.662c0,0-0.001,0-0.002,0l0,0C19.279,10.662,19.28,10.662,19.281,10.662 M19.278,10.662C19.276,10.663,19.276,10.663,19.278,10.662 M16.061,31.238C16.061,31.239,16.061,31.239,16.061,31.238 M16.061,31.241C16.06,31.244,16.06,31.244,16.061,31.241 M16.06,31.243C16.058,31.248,16.058,31.248,16.06,31.243 M31.946,9.2C31.946,9.188,31.946,9.197,31.946,9.2 M16.058,31.247C16.057,31.253,16.057,31.253,16.058,31.247 M27.947,11.245C27.946,11.243,27.935,11.213,27.947,11.245 M27.926,11.151C27.925,11.149,27.926,11.158,27.926,11.151 M27.913,11.108c-0.001,0-0.001,0-0.001-0.002C27.912,11.107,27.912,11.107,27.913,11.108 M8.032,25.091c0.004,0.006,0.01,0.011,0.014,0.016C8.042,25.102,8.036,25.097,8.032,25.091z M8.078,25.142c0.003,0.004,0.008,0.007,0.011,0.01C8.086,25.148,8.082,25.146,8.078,25.142z M8.155,25.203c-0.001-0.001-0.003-0.003-0.005-0.004C8.151,25.2,8.154,25.202,8.155,25.203z M8.656,29.115c-0.001-0.002-0.001-0.004-0.002-0.005C8.655,29.111,8.655,29.113,8.656,29.115z M8.773,29.223c-0.004-0.004-0.007-0.006-0.012-0.01C8.766,29.217,8.769,29.219,8.773,29.223z M16.053,31.259C16.057,31.25,16.057,31.25,16.053,31.259";

var ctIconTwPath = "M19.484,17.167c0.96-2.996,2.133-4.937,3.483-6.344c1.007-1.051,1.527-1.383,0.936-0.228c0.262-0.209,0.637-0.487,0.928-0.636c1.635-0.771,1.519-0.125,0.393,0.568c3.071-1.1,2.965,0.3-0.284,0.997c2.655,0.051,5.479,1.74,6.293,5.334c0.111,0.498-0.022,0.451,0.487,0.541c1.1,0.194,2.134,0.183,3.143-0.137c-0.109,0.743-1.092,1.227-2.624,1.546c-0.568,0.118-0.684,0.087-0.003,0.24c0.838,0.188,1.775,0.237,2.766,0.19c-0.771,0.889-2.002,1.343-3.524,1.362c-0.952,3.477-3.127,5.967-5.88,7.529C19.129,31.797,9.719,31.266,5,24.597c3.097,2.431,7.685,2.965,11.091-0.422c-2.231,0.001-2.81-1.671-1.041-2.573c-1.675-0.018-2.74-0.547-3.366-1.508c-0.237-0.364-0.24-0.392,0.148-0.671c0.426-0.307,1.006-0.445,1.604-0.491c-1.734-0.497-2.795-1.403-3.163-2.618c-0.121-0.401-0.14-0.381,0.27-0.485c0.399-0.102,0.914-0.156,1.375-0.178c-1.362-0.826-2.176-1.839-2.382-2.958c-0.196-1.057,0.005-0.786,0.797-0.483C13.87,13.562,17.396,15.015,19.484,17.167L19.484,17.167z";

var ctIconDrPath = "M9.65,18.441c3.682,0.561,7.509-0.054,10.764-1.687c-1.649-2.583-3.947-4.435-6.684-5.129C11.579,13.241,10.068,15.665,9.65,18.441z M22.185,20.524c-0.282-0.855-0.622-1.67-1.012-2.437c-2.698,1.368-5.762,2.09-8.841,2.09c-0.934,0-1.869-0.066-2.795-0.202c0,0.009-0.003,0.017-0.003,0.024c0,2.943,1.223,5.604,3.183,7.508c1.46-2.525,3.898-4.654,6.974-6.058C20.493,21.084,21.326,20.778,22.185,20.524z M20,8c6.617,0,12,5.384,12,12c0,6.618-5.383,12-12,12c-6.614,0-12-5.383-12-12C8,13.384,13.386,8,20,8z M23.024,30.02c0.354-2.817,0.186-5.545-0.414-8.005c-3.824,1.138-7.039,3.438-8.699,6.491c1.718,1.231,3.818,1.961,6.088,1.961C21.052,30.467,22.066,30.309,23.024,30.02z M22.5,17.347c0.451,0.878,0.841,1.816,1.162,2.801c2.201-0.471,4.514-0.586,6.8-0.324c-0.047-2.893-1.275-5.505-3.224-7.373c-0.564,1.361-1.775,2.779-3.476,4.042C23.354,16.795,22.933,17.08,22.5,17.347z M30.377,21.355c-2.143-0.254-4.278-0.14-6.289,0.285c0.592,2.399,0.797,5.024,0.546,7.742C27.701,27.861,29.917,24.881,30.377,21.355z M25.975,11.414c-1.694-1.182-3.754-1.88-5.975-1.88c-1.626,0-3.168,0.375-4.544,1.042c2.548,1.004,4.698,2.922,6.285,5.438c0.379-0.235,0.749-0.486,1.107-0.752C24.501,14.033,25.655,12.601,25.975,11.414z";

var ctIconLiPath = "M29.378,8.936H10.623C9.724,8.936,9,9.642,9,10.512v18.966c0,0.88,0.724,1.586,1.623,1.586h18.755c0.889,0,1.622-0.707,1.622-1.586V10.512C31,9.642,30.267,8.936,29.378,8.936z M15.664,27.462h-3.318V17.47h3.318V27.462z M14.005,16.104h-0.018c-1.118,0-1.833-0.77-1.833-1.732c0-0.981,0.743-1.723,1.879-1.723c1.136,0,1.833,0.742,1.851,1.723C15.884,15.334,15.169,16.104,14.005,16.104z M27.645,27.462h-3.317v-5.354c0-1.339-0.477-2.255-1.688-2.255c-0.916,0-1.457,0.614-1.705,1.219c-0.081,0.211-0.1,0.505-0.1,0.807v5.583h-3.328c0,0,0.046-9.057,0-9.991h3.328v1.411c0.439-0.678,1.229-1.65,2.988-1.65c2.19,0,3.822,1.43,3.822,4.501L27.645,27.462L27.645,27.462z";


var ctIconEmUp = Raphael("ctIconEmUp", 40, 40);
var ctIconEmUpPath = ctIconEmUp.path(ctIconEmPath);
ctIconEmUpPath.attr("fill", ctIconGradUp);
ctIconEmUpPath.attr("stroke-width", 0);
ctIconEmUpPath.attr("stroke-opacity", 0);

var ctIconEmOver = Raphael("ctIconEmOver", 40, 40);
var ctIconEmOverPath = ctIconEmOver.path(ctIconEmPath);
ctIconEmOverPath.attr("fill", ctIconGradOver);
ctIconEmOverPath.attr("stroke-width", 0);
ctIconEmOverPath.attr("stroke-opacity", 0);

var ctIconPhUp = Raphael("ctIconPhUp", 40, 40);
var ctIconPhUpPath = ctIconPhUp.path(ctIconPhPath);
ctIconPhUpPath.attr("fill", ctIconGradUp);
ctIconPhUpPath.attr("stroke-width", 0);
ctIconPhUpPath.attr("stroke-opacity", 0);

var ctIconPhOver = Raphael("ctIconPhOver", 40, 40);
var ctIconPhOverPath = ctIconPhOver.path(ctIconPhPath);
ctIconPhOverPath.attr("fill", ctIconGradOver);
ctIconPhOverPath.attr("stroke-width", 0);
ctIconPhOverPath.attr("stroke-opacity", 0);

var ctIconTwUp = Raphael("ctIconTwUp", 40, 40);
var ctIconTwUpPath = ctIconTwUp.path(ctIconTwPath);
ctIconTwUpPath.attr("fill", ctIconGradUp);
ctIconTwUpPath.attr("stroke-width", 0);
ctIconTwUpPath.attr("stroke-opacity", 0);

var ctIconTwOver = Raphael("ctIconTwOver", 40, 40);
var ctIconTwOverPath = ctIconTwOver.path(ctIconTwPath);
ctIconTwOverPath.attr("fill", ctIconGradOver);
ctIconTwOverPath.attr("stroke-width", 0);
ctIconTwOverPath.attr("stroke-opacity", 0);

var ctIconDrUp = Raphael("ctIconDrUp", 40, 40);
var ctIconDrUpPath = ctIconDrUp.path(ctIconDrPath);
ctIconDrUpPath.attr("fill", ctIconGradUp);
ctIconDrUpPath.attr("stroke-width", 0);
ctIconDrUpPath.attr("stroke-opacity", 0);

var ctIconDrOver = Raphael("ctIconDrOver", 40, 40);
var ctIconDrOverPath = ctIconDrOver.path(ctIconDrPath);
ctIconDrOverPath.attr("fill", ctIconGradOver);
ctIconDrOverPath.attr("stroke-width", 0);
ctIconDrOverPath.attr("stroke-opacity", 0);

var ctIconLiUp = Raphael("ctIconLiUp", 40, 40);
var ctIconLiUpPath = ctIconLiUp.path(ctIconLiPath);
ctIconLiUpPath.attr("fill", ctIconGradUp);
ctIconLiUpPath.attr("stroke-width", 0);
ctIconLiUpPath.attr("stroke-opacity", 0);

var ctIconLiOver = Raphael("ctIconLiOver", 40, 40);
var ctIconLiOverPath = ctIconLiOver.path(ctIconLiPath);
ctIconLiOverPath.attr("fill", ctIconGradOver);
ctIconLiOverPath.attr("stroke-width", 0);
ctIconLiOverPath.attr("stroke-opacity", 0);

$('.ctIcon').click(
	function() {
		var footerCtActive = $(this).parent();
		if ( $(footerCtActive).hasClass('open') ) {
			$(footerCtActive).removeClass('open');
			$(footerCtActive).animate({width:40}, 100, function() {
				//$(footerCtActive).find('.ctIconInfo').width(0);
				$(footerCtActive).find('.ctIconUp').fadeIn(800);
			});
			
		} else {
			$(footerCtActive).addClass('open');
			//$(footerCtActive).children('.ctIconInfo').width(140);
			$(footerCtActive).find('.ctIconUp').fadeOut(0);
			$(footerCtActive).animate({width:200}, 100, function() {
				$(footerCtActive).siblings('.open').animate({width:40}, 100, function() {
					//$(footerCtActive).siblings('.open').children('.ctIconInfo').width(0);
					$(footerCtActive).siblings('.open').find('.ctIconUp').fadeIn(800, function() {
						$(footerCtActive).siblings('.open').removeClass('open');
					});
				});
			});
		}
	}
);

/* END CONTACT ICONS */




/* START GALLERY */
// define global vars
var newImage = 'img/intro.png';
var imgWidth = 0;
var imgHeight = 0;
var imgOrientation = '';
var imgMarginTop = 0;

var imgInfoWidth = 0;
var imgInfoHeight = 0;
var imgInfoPadding = 5;
var imgInfoMargin = 5;

var imgViewWidth = 0;
var imgViewHeight = 0;
var imgViewOrientation = '';

var imgNavDir = '';

var imgInfo = 'Use the arrows or the thumbnails on the left to view images';

// load the new image
function loadImage(newImage) {
		$.ajax({
			url: newImage,
			beforeSend: function () {
				},
			success: function (data) {
				},
			complete: function () {
				$('#imgHidden').attr('src', newImage);
				//getImageSize();
				},
			error: function () {
				//alert('error');
				}
		});
		return false;
}

$('#imgHidden').imagesLoaded(getImageSize)

// get size of new image, define margin and orientation
function getImageSize() {
		imgWidth = $('#imgHidden').width();
		imgHeight = $('#imgHidden').height(); 
		imgViewHeight = $('#view').height();

		// calculate top margin from image & frame height
		imgMarginTop = (imgViewHeight-imgHeight)/2; 
	
		//set orientation
		// landscape
		if (imgWidth > imgHeight) {
			imgOrientation = 'landscape';
		}
		// portrait
		if (imgWidth < imgHeight) {
			imgOrientation = 'portrait';
		}
		// square
		if (imgWidth == imgHeight) {
			imgOrientation = 'square';
		}
		$('#imgHidden').addClass(imgOrientation);
	
	imageOut()
}

function imageOut() {
	$('#imgHolder').animate({'opacity':0}, 200, function() {
		imageSwitch()
	});


}

function imageSwitch() {
	$('#imgHolder').removeClass('landscape portrait square').addClass(imgOrientation); // set orientation

	// apply changes
	$('#imgVisible').attr('src', newImage); // apply src
	$('#imgInfo p').html(imgInfo); // apply info

	$('#imgHolder').css({width:imgWidth}); // set image dimensions
	$('#imgHolder').css({height:imgHeight}); 

	imgInfoHeight = $('#imgInfo').height(); // get info height
	imgInfoHeight += imgInfoPadding + imgInfoMargin; // adjust
	imgInfoHeight /= 2;

	imgMarginTop -= imgInfoHeight; // adjust top margin to info

	if (imgMarginTop <= 0) {imgMarginTop = 0} // dont overflow at top
	$('#imgHolder').css({marginTop:imgMarginTop}); // apply top margin

	imageIn();
}

function imageIn() {
	$('#loading').fadeOut(200, function() {
		$('#imgHolder').animate({'opacity':1},600);
	});
}


function getViewOrientation() {
	imgViewWidth = $('#view').width();
	imgViewHeight = $('#view').height();

	//set orientation
	// landscape
	if (imgViewWidth > imgViewHeight) {
		imgViewOrientation = 'landscape';
	}
	// portrait
	if (imgViewWidth < imgViewHeight) {
		imgViewOrientation = 'portrait';
	}
	// square
	if (imgViewWidth == imgViewHeight) {
		imgViewOrientation = 'square';
	}

	$('#view').removeClass('landscape portrait square').addClass(imgViewOrientation);
	//$('#debug').html(imgViewOrientation);
}

/* Page loaded... */
$(document).ready(function(){
	// initialise page
	$('#loading').fadeOut(0);
	loadImage(newImage);
	getViewOrientation();

// image thumbnials
	$("#thumbs a").click(function(){
		newImage = $(this).attr('href');
		//imgInfo = $(this).attr('rel');
		imgInfo = $(this).attr('rel');

		// check not same image
		if ( newImage != $('#imgVisible').attr('src') ) {
			// change thumbs
			$('#thumbs a').removeClass('current');
			$(this).addClass('current');
			// aaaaaand GO!
			$('#loading').fadeIn(200, function() { loadImage(newImage); });
		}
		
		return false;
	});

// image navigation
	$("#imgNav div").click(function(){
		if ($('#thumbs a.current').length == 0) { // if at start
			if ( $(this).hasClass('next') ) { 
				newImage = $('#thumbs a').first().attr('href');
				imgInfo = $('#thumbs a').first().attr('rel');
				$('#thumbs a').first().addClass('current');
			}
			if ( $(this).hasClass('prev') ) { 
				newImage = $('#thumbs a').last().attr('href');
				imgInfo = $('#thumbs a').last().attr('rel');
				$('#thumbs a').last().addClass('current');
			}
		} else {
			if ( $(this).hasClass('next') ) { 
				if ( $('#thumbs a').last().hasClass('current') ) {
					newImage = $('#thumbs a').first().attr('href');
					imgInfo = $('#thumbs a').first().attr('rel');
					$('#thumbs a').last().removeClass('current');
					$('#thumbs a').first().addClass('current');
				} else {
					newImage = $('#thumbs a.current').next().attr('href');
					imgInfo = $('#thumbs a.current').next().attr('rel');
					$('#thumbs a.current').removeClass('current').next().addClass('current');
				}
			}
			if ( $(this).hasClass('prev') ) {
				if ( $('#thumbs a').first().hasClass('current') ) {
					newImage = $('#thumbs a').last().attr('href');
					imgInfo = $('#thumbs a').last().attr('rel');
					$('#thumbs a').first().removeClass('current');
					$('#thumbs a').last().addClass('current');
				} else {
					newImage = $('#thumbs a.current').prev().attr('href');
					imgInfo = $('#thumbs a.current').prev().attr('rel');
					$('#thumbs a.current').removeClass('current').prev().addClass('current');
				}
			}
		}

		// aaaaaand GO!
		$('#loading').fadeIn(200, function() { loadImage(newImage); });
		
		return false;
	});
});

var resizeTimerOn = 0; // resizing on/off

$(window).resize( 
	function() {
		if (resizeTimerOn == 0) {
			resizeTimerOn = 1;
			var resizeTimer=setTimeout("resizeRefresh()",2000);
		}
	}
);

function resizeRefresh() {
	getViewOrientation();
	getImageSize();
	resizeTimerOn = 0;
}

/* END GALLERY */




















