(function($){
	var baseURL="http://"+window.location.hostname;
	var pathURL=baseURL+"/wp-content/themes/pcsupportgroup";
	var currentURL=window.location;
	var map2;
	
	// Load
	$("input[type=submit]").val("");
	if ($(".ie8,.ie7").length==0) {
		$("#search dd input").corner("2px");
		$(".enquiry_box,.testimonials_box,.testimonials_box h3,.news_box,.news_box h3,#content_right h6 a,#content_right blockquote,.enquiry_form dd input,.enquiry_form dd select,.enquiry_form dd textarea,.enquiry_form h3,#form_submit,#contact_form h3,.bfa_membership,#recaptcha_image,.telephone_contact,.widget,.widget h3,#map_area,#local_map,#local_map_area,.enquiry_form,#btm_enquiry_form,#btm_enquiry_form dd input,#btm_enquiry_form dd textarea,.testimonial_panel,.widget-container,.item_add,#content_left h5,.widget_text,.widget_text h3").corner("4px");
	}
	if ($("#map_area").length>0) { localMap(); }
	loadMap($("#footer_map").text(),13,"footer_map");
	$("#content_right blockquote p").append('&nbsp; <img src="'+pathURL+'/images/blockquote_end.png" alt="">');
	$("h3.faq").css("cursor","pointer").mouseover(function(){ $(this).css("color","#6fb402"); }).mouseout(function(){ $(this).not(".active").css("color","#81387E"); }).live("click",function(){
		$("h3.faq").nextUntil("h3").hide();
		$("h3.active").removeClass("active").css("color","#81387E");
		$(this).addClass("active").nextUntil("h3").fadeIn();
	}).nextUntil("h3").hide();
	$("h3.active").live("click",function(){
		$("h3.faq").nextUntil("h3").hide();
		$(this).removeClass("active");
	}); 
	$(".page-id-9 a[href$='.doc'],.page-id-9 a[href$='.docx'],.page-id-9 a[href$='.pdf']").addClass("document");
	$(".proposition:first").addClass("active").show();
	//$("#entry_points .entry_point:first").addClass("active");
	setTimeout(function(){ $("#brands").css("width",$("#brands ul").width()+"px"); },500);
	$(".testimonial_panel").each(function(){
		var thisItem = $(this);
		thisItem.find("p:first").nextAll().wrapAll('<div class="expand">');
		thisItem.find(".expand").css("height",thisItem.find(".expand").height()+"px").hide().after('<p class="control control_down">Expand &amp; read more</p>');
		$(".control").corner("bl br 4px");
		thisItem.find(".expand :first-child").css("margin-top","0px");
		if (thisItem.find(".expand").length==0) { thisItem.css("padding-bottom","5px"); }
	});
	$(".control_down").live("click",function(){
		var thisItem = $(this);
		var thisParent = thisItem.parent();
		thisItem.removeClass("control_down").addClass("control_up").text("Close");
		thisParent.find(".expand").slideDown();
	});
	$(".control_up").live("click",function(){
		var thisItem = $(this);
		var thisParent = thisItem.parent();
		thisItem.removeClass("control_up").addClass("control_down").text("Expand & read more");
		thisParent.find(".expand").slideUp();
	});
	$("#content_left a[href$='.pdf'],#content_left a[href$='.doc'],#content_left a[href$='.docx']").not(".press_panel a").parent().addClass('press_panel');
	$("#content_left a[href$='.mp3']").not(".press_panel a").parent().addClass('podcast_panel');
	if ($(".home").length>0) {
		var i=0;
		startTimer = setInterval(function(){
			var thisItem = $("#mast .active");
			var prevItems = thisItem.prevAll(".proposition").length;
			var nextItems = thisItem.nextAll(".proposition").length;
			if (i>4) { i=0; }
			if (i==0) { $(".entry_point:first").addClass("active"); }
			if (nextItems>0) {
				thisItem.fadeOut().removeClass("active").next(".proposition").fadeIn().addClass("active");
				if (i>0) {
					$("#entry_points .active").removeClass("active").next(".entry_point").fadeIn().addClass("active");
				}
			} else {
				thisItem.fadeOut().removeClass("active");
				$("#mast .proposition:first").fadeIn().addClass("active");
				$("#entry_points .active").removeClass("active");
				//$("#entry_points .entry_point:first").fadeIn().addClass("active");
			}
			i++;
		},7000);
	}

	//Interactive
	jQuery.fn.fullLink=function(link){jQuery(this).each(function(){var thisElem=jQuery(this);if(jQuery("a",thisElem).length>0){thisElem.css("cursor","pointer").click(function(){if(link){window.location=jQuery("a:nth-child("+link+")",this).attr("href");}else{window.location=jQuery("a",this).attr("href");}});}});}
	preload_image = new Image(); 
    preload_image.src=pathURL+"/images/sub_nav.png";  
	$(".sub-menu").each(function(){ $("li:last",this).css("border","0px"); }).mouseover(function(){
		$(this).parent().addClass("current-menu-item");
	}).mouseout(function(){
		$(this).parent().removeClass("current-menu-item");
	});
	$(".entry_point,.press_panel,.podcast_panel").fullLink();
	/*$(".entry_point").live("click",function(){
		clearInterval(startTimer);
		var thisItem = $(this);
		var thisId = thisItem.attr("data-id");
		$("#entry_points .active").removeClass("active");
		thisItem.addClass("active");
		$("#mast .proposition").not($("#mast ."+thisId)).fadeOut();
		$("#mast ."+thisId).fadeIn();
	});*/
	$("#search dd input").live("focus",function(){
		$(this).animate({width:"250px"});
	}).live("blur",function(){
		var thisInput = $(this);
		if (thisInput.val()=="") { thisInput.animate({width:"150px"}); }
	});
	$("input[type=text]").each(function(){
		var thisVal=$(this).val();
		$(this).bind("focus",function(){
			if ($(this).val()==thisVal) { $(this).val(""); }
		}).bind("blur",function(){
			if ($(this).val()=="") { $(this).val(thisVal); }
		});
	});
	$(".enquiry_submit").css("opacity",1);
	$(".enquiry_form form").live("submit",function(event){
		event.preventDefault();
		var thisForm = $(this);
		var thisId = thisForm.attr("data-id");
		thisForm.find(".enquiry_submit").attr("disabled","disabled").animate({opacity:0.6},150);
		$.post(pathURL+"/php/enquiry_form.php",$(this).serialize(),function(data){
			if (data.status==0) {
				thisForm.find(".enquiry_feedback").hide().html(data.error).fadeIn();
				thisForm.find(".enquiry_submit").removeAttr("disabled").animate({opacity:1},150);
			} else {
				window.location.href=baseURL+"/contact-us/thank-you/";
			}
		},"json");
	});
	
	$("#btm_enquiry_submit").css("opacity",1);
	$("#btm_enquiry_form form").live("submit",function(event){
		event.preventDefault();
		var thisForm = $(this);
		thisForm.find("#btm_enquiry_submit").attr("disabled","disabled").animate({opacity:0.6},150);
		$.post(pathURL+"/php/btm_enquiry_form.php",$(this).serialize(),function(data){
			if (data.status==0) {
				$("#btm_enquiry_feedback").hide().html(data.error).fadeIn();
				thisForm.find("#btm_enquiry_submit").removeAttr("disabled").animate({opacity:1},150);
			} else {
				window.location.href=baseURL+"/contact-us/thank-you/";
			}
		},"json");
	});
	
	$("#hear").change(function(){
		var thisOption = $("option:selected",this).val();
		if (thisOption=="Other") { $("#contact_form .other").fadeIn(); }
		else { $("#contact_form .other").fadeOut(); }
	});
	$("#contact_form #submit").css("opacity",1);
	$("#contact_form").live("submit",function(event){
		var thisForm = $(this);
		thisForm.find("#submit").attr("disabled","disabled").animate({opacity:0.6},150);
		$.post(pathURL+"/php/contact_form.php",thisForm.serialize(),function(data){
			if (data.status==0) {
				thisForm.find(".feedback").hide().html(data.error).fadeIn();
				thisForm.find("#submit").removeAttr("disabled").animate({opacity:1},150);
			} else {
				window.location.href=baseURL+"/contact-us/thank-you/";
			}
		},"json");
		event.preventDefault();
	});
	
	// Functions
	function loadMap(address,zoom,div) {
		geocoder = new google.maps.Geocoder();
		geocoder.geocode({'address':address},function(results,status) {
			if (status == google.maps.GeocoderStatus.OK) {
				var center = results[0].geometry.location;
				var myOptions = { zoom:zoom,center:center,mapTypeId:google.maps.MapTypeId.ROADMAP };
				var map = new google.maps.Map(document.getElementById(div),myOptions);
				var marker = new google.maps.Marker({map:map,position:center});
			}
		});
	}
	function localMap() {
		geocoder = new google.maps.Geocoder();
		var center = new google.maps.LatLng(54.686534,-3.131104);
		var myOptions = { zoom:5,center:center,mapTypeId:google.maps.MapTypeId.ROADMAP };
		var map2 = new google.maps.Map(document.getElementById('local_map'),myOptions);
		var image = new google.maps.MarkerImage(pathURL+'/images/marker.png',new google.maps.Size(24,37),new google.maps.Point(0,0),new google.maps.Point(12,37));
		var shadow = new google.maps.MarkerImage(pathURL+'/images/shadow.png',new google.maps.Size(46,37),new google.maps.Point(0,0),new google.maps.Point(12,37));
		var shape = {coord:[22,0,22,1,23,2,23,3,23,4,23,5,23,6,23,7,23,8,23,9,23,10,23,11,23,12,23,13,23,14,23,15,23,16,23,17,23,18,23,19,23,20,23,21,23,22,23,23,22,24,18,25,17,26,17,27,17,28,16,29,16,30,15,31,15,32,14,33,14,34,14,35,13,36,11,36,11,35,10,34,10,33,9,32,9,31,8,30,8,29,7,28,7,27,7,26,6,25,1,24,0,23,0,22,0,21,0,20,0,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,0,5,0,4,0,3,0,2,1,1,1,0,22,0],
	type: 'poly'};
		$("#local_map").mouseover(function(){
			$(this).stop().animate({height:"340px"},function(){ google.maps.event.trigger(map2,'resize'); /*map2.panTo(center);*/ });
			$("#local_map_area").stop().animate({height:"340px"});
		}).mouseout(function(){
			$(this).stop().animate({height:"180px"},function(){ google.maps.event.trigger(map2,'resize'); /*map2.panTo(center);*/ });
			$("#local_map_area").stop().animate({height:"180px"});
		});
		$("#map_area li").each(function(){
			var thisItem = $(this);
			var thisLink = thisItem.find("a");
			var thisHref = thisLink.attr("href");
			var thisCoords = thisItem.attr("data-coords");
			var thisId = thisItem.attr("data-id");
			if (thisCoords) {
				var sw=thisCoords.split(',');
				var center = new google.maps.LatLng(sw[0],sw[1]);
				var marker = new google.maps.Marker({map:map2,position:center,icon:image,shadow:shadow,shape:shape});
				google.maps.event.addListener(marker,'click',function() { window.location=thisHref; });
			} /*else {
				geocoder.geocode({'address':thisLink.text()+", UK"},function(results,status) {
					if (status == google.maps.GeocoderStatus.OK) {
						var center = results[0].geometry.location;
						var thisCoords = String(center);
						$.post(pathURL+"/php/save_coords.php",{id:thisId,coords:thisCoords},function(){
							var marker = new google.maps.Marker({map:map2,position:center,icon:image,shadow:shadow,shape:shape});
							google.maps.event.addListener(marker,'click',function() { window.location=thisHref; });
						});
					}
				});
			}*/
		});
	}
	
	// Cart
	simpleCart.checkoutTo = PayPal;
	simpleCart.email = "accounts@pcsupportgroup.com";
	simpleCart.currency = GBP;
	simpleCart.cartHeaders = ["Remove","Quantity","Name","Description"];
})(this.jQuery);
