// UTF8‼
$(document).ready(function(){

	if (/MSIE\s(5\.5|6\.)/.test(navigator.userAgent)) {
		DD_belatedPNG.fix('#logo,#nav,#nav .container,#feature,#foot,#contact_form_submit,#portfolio_link');
	}

	// Tabbed Content
	$('#strip').css({backgroundPosition:"0px 11px"});
	$('#stripcontent').css({'overflow':'hidden','height':'267px'});
	$('#content-border').css({'height':'273px'});
	function f_content_scroll(fv_id) {
		$('#subnav a').removeClass('current');
		$('#subnav a[rel="' + fv_id + '"]').addClass('current');
		// Anchor Offsets
		switch (location.hash.slice(1)) {
			case 'studio':
				var offset = 952;
			break;
			case 'contact':
				var offset = 1904;
			break;
			default:
				var offset = 0;
			break;
		}
		switch (fv_id) {
			case 'studio':
				var x = -952 + offset;
			break;
			case 'contact':
				var x = -1904 + offset;
			break;
			default : var x = 0 + offset;
		}
		$('#content-scroll').stop().animate({ 
			left:x + 'px'
		},1000);
		$('#strip').stop().animate(
			{backgroundPosition:(x*2) + "px 11px"}, 
			1200,
			function(){
				switch (fv_id) {
					case 'services':
						// Check If Home Page Needs Loading
						if ($('#homepagecontent').length == 0){
							f_load(v_url_root);
						}
					break;
					case 'studio':
						try{pageTracker._trackPageview('/photography/studio/');}catch(err){}
					break;
					case 'contact':
						f_init_contact();
						try{pageTracker._trackPageview('/photography/contact/');}catch(err){}
					break;
				}
			}
		);
	}

	// Clicks
	$('#nav a').click(function(){
		try{pageTracker._trackEvent('Photo Nav','Click',$(this).attr('href') + ' (Nav)');}catch(err){}
		location.href = $(this).attr('href');
		return false;
	});
	$('#head').css({'cursor':'pointer'}).click(function(){
		f_content_scroll('services');
		try{pageTracker._trackEvent('Photo Nav','Click',v_url_root + ' (Head)');}catch(err){}
		return false;
	});
	$('#subnav a').click(function(){
		f_content_scroll($(this).attr('rel'));
		try{pageTracker._trackEvent('Photo Nav','Click',$(this).attr('href') + ' (Sub Nav)');}catch(err){}
		return false;
	});
	$('#cta a').click(function(){
		f_content_scroll($(this).attr('rel'));
		location.href = '#head';
		try{pageTracker._trackEvent('Photo Nav','Click',$(this).attr('href') + ' (CTA)');}catch(err){}
		return false;
	});
	$('#services').click(function(){
		try{pageTracker._trackEvent('Photo Nav','Click',v_url_root + '#services (Feature)');}catch(err){}
	});
	$('#studio').click(function(){
		try{pageTracker._trackEvent('Photo Nav','Click',v_url_root + '#studio (Feature)');}catch(err){}
	});
	$('#foot a:not(#terms_link)').click(function(){
		//alert($(this).attr('href') + ' (Foot)');
		try{pageTracker._trackEvent('Photo Nav','Click',$(this).attr('href') + ' (Foot)');}catch(err){}
		location.href = $(this).attr('href');
		return false;
	});

	if (swfobject.hasFlashPlayerVersion("7.0.19.0")) {
		// Logo
		swfobject.embedSWF(
			v_url_root + "media/swf/logo.swf",
			"logo",
			154,154,
			"7.0.19.0",
			v_url_root + "media/swf/expressInstall.swf",
			{},
			{
				menu:"false",
				wmode:"transparent"
			},{
				salign:"left",
				id:"logo",
				name:"logo"
			}
		);
		// Photo Services Video
		swfobject.embedSWF(
			v_url_root + "media/swf/monoslideshow.swf",
			"services_video",
			952,267,
			"7.0.19.0",
			v_url_root + "media/swf/expressInstall.swf",
			{
				showLogo:false,
				showVersionInfo:false,
				dataFile:v_url_root + 'portfolio/xml/'
			},{
				bgcolor:"#1d3a4e",
				menu:"false",
				wmode:"opaque"
			},{
				id:"services_video",
				name:"services_video"
			}
		);
	}

	// Contact
	function f_init_contact() {

		// Highlighting Current Inputs/Labels
		$("#contact_form input,#contact_form textarea")
			.focus(function(){
				try{pageTracker._trackEvent('Photo Contact Form','Focus',$('label[for=' + $(this).attr('name') + ']').text().slice(0,$('label[for=' + $(this).attr('name') + ']').text().indexOf(' :')));}catch(err){}
				$(this).parents(".row").addClass('hover');
			})
			.blur(function(){
				$(this).parents(".row").removeClass('hover');
					$(this).valid();
			});

		$('#contact_form').validate({
			highlight: function(element, errorClass) {
				try{pageTracker._trackEvent('Photo Contact Form','Error',$('label[for=' + $(element).attr('name') + ']').text().slice(0,$('label[for=' + $(element).attr('name') + ']').text().indexOf(' :')));}catch(err){}
				$(element).parents(".row").addClass(errorClass);
			},
			unhighlight: function(element, errorClass) {
				$(element).parents(".row").removeClass(errorClass);
			},
			errorElement: "span",
			errorPlacement: function(error, element) {
				error.appendTo(element.parent()).click(function(){
					$(this).hide().parent().children('input,textarea').focus();
				});
			},
			submitHandler: function(form) {
				try{pageTracker._trackEvent('Photo Contact Form','Submit','Post');}catch(err){}
				// Post Data
				$.post($('#contact_form').attr('action'),$('#contact_form').serialize(),function(data){
					try{
						var d = new Date();
						var cid = d.getUTCFullYear()+"-"+("00"+(d.getUTCMonth()+1)).substr(-2)+"-"+("00"+d.getUTCDate()).substr(-2)+"_"+("00"+d.getUTCHours()).substr(-2)+"-"+("00"+d.getUTCMinutes()).substr(-2)+"-"+("00"+d.getUTCSeconds()).substr(-2);
						pageTracker._setCustomVar(1,"CID",cid,1); // Slot 1, Name, Value, Visitor Level
						pageTracker._trackEvent('Photo Contact Form','Submit','Response');
					}catch(err){}
					// Response Message
					alert(data);
					try{pageTracker._trackPageview('/photography/contact/submitted/');}catch(err){}
					$('#contact_form input, #contact_form textarea').removeAttr('disabled');
					$('#contact_form_status').fadeOut('fast');
					$("#contact_form input[type='submit']").fadeTo('fast',1);
				});
				// Disable Elements (To prevent double submission)
				$('#contact_form input, #contact_form textarea').attr('disabled','disabled');
				$('#contact_form_status').hide().html('Sending. Please Wait…').fadeIn('fast');
				$("#contact_form input[type='submit']").fadeTo('fast',0.25);
			}
		});

		if (typeof google != 'undefined') {
			var latlng = new google.maps.LatLng(50.965,-2.628);
			var myOptions = {
				mapTypeId:google.maps.MapTypeId.ROADMAP,
				center:latlng,
				zoom:12,
				disableDefaultUI:true,
				navigationControl:true,
				navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL},
				mapTypeControl:false,
				scaleControl:true
			};
			var latlng = new google.maps.LatLng(50.9461,-2.6105);
			var map = new google.maps.Map(document.getElementById("map"),myOptions);
			var marker = new google.maps.Marker({position:latlng,map:map,icon:v_url_root + 'media/img/marker.png'});
			var marker_html = '' +
				'<div id="map_marker_html">' +
					'<strong>Flaydemouse</strong><br />' +
					'8 Buckland Road, Pen Mill Trading Estate<br />' +
					'Yeovil, Somerset, BA21 5EA <a href="http://maps.google.com/maps?f=d&saddr=&daddr=Flaydemouse,+Yeovil,+Somerset,+BA21+5EA,+UK" onclick="window.open(this.href);return false;">(Directions)</a><br />' +
					'<strong>T: 01935 479 453</strong>' +
				'</div>';
			function f_infowindow() {
				if (typeof infowindow != 'undefined') infowindow.close();
				infowindow = new google.maps.InfoWindow({content:marker_html});
				infowindow.open(map,marker);
			}
			google.maps.event.addListener(marker,'click',function(){
				f_infowindow();
			});
			f_infowindow();
		}
		
	}

	// Trigger Current Tab
	if (location.hash.slice(1) == '' || location.hash.slice(1) == 'head') {
		if (location.href.replace(v_url_root,'').replace(location.hash,'') == '') {
			f_content_scroll('services');
		}
	} else {
		f_content_scroll(location.hash.slice(1));
	}
});
