$(document).ready(function() {
	//microPage();
	services();
	commentsForm();
	contactForm();
	$('#header').supersleight();
	$('#site_information').supersleight({ 'apply_positioning' : false });
});



function addHighlight(link){
	
	$(link).each(function () {
	  
      if (this.href == window.location.href) {
      	
      	   $(this).addClass('highlight');

        }
    });
	
}

function services(){
	
	// animate the main content
	$("#services_container").fadeIn("slow");
	$("#services_container").animate({"left": "+=981px"}, "slow");

	// highlight the currently selected links
	addHighlight("#services_overview div a");
	addHighlight("#service_indicator_docks a");

  // fade in the grey arrow
//  $("#service_indicator_docks a.highlight").animate({opacity: 1}, 3000);
  $("#service_indicator_docks a.highlight").fadeIn("slow");
	
	
	// highlight each service on mouseover grey arrows also
	$("#service_indicator_docks a").mouseover(function(){
	
			current = $(this).attr("class");
		
			currentLink = $("#services_overview #" + current + " a");
			
			// if it doesnt have it already, add class and then remove on mouseout
			if(!currentLink.hasClass('highlight')){
				
				currentLink.addClass('highlight');
				
				$(this).mouseout(function(){
					
					currentLink.removeClass('highlight');
					
				});
			}
		
		}
	
	);
	
	// load the appropriate content for each service sub-section
/*	$("#services_container a.more").each(function(){
		
		$(this).click(function(){
				
			$(".service_process #sub-sections").html("<img id='loading' src='http://www.clarelindley.com/ip/wp-content/themes/infinitepath/images/ajax-loader.gif' />");
			$(".service_process #sub-sections").load(this.href);
	
			return false;

		
		});
		
	});*/
	
	
}


function ie7DialogFix(id) {
	//Fix for IE7 css rendering bug
	var parent = $(id).parent(".ui-dialog");
	var width = $(id).width() + 10;
	$(parent).find(".ui-dialog-titlebar").css({ width: ""+width+"px" });
}

function microPage() {
	$('a.micro_page').live("click", function(){
		var url = $(this).attr('href')+' #micro_page';
		$('body').append('<div id="scratch_content"></div>');
		$('#scratch_content').hide();
		$('#scratch_content').load(url, '', function() {
			$this = $('#scratch_content').dialog({
						title: ''+$('#scratch_content #micro_page_contentT').text()+'',
						width: 'auto',
						modal: true,
						resizable: false,
						open: function(event, ui) {
							ie7DialogFix($(this));	
						},
						close: function(event, ui) {
							$this.remove();
						}
					});											 
		});
		return false;
	});
};


/*function services() {
	$("#home #service_webdesign a").attr("href", "/wp/services/#go-services_webdesign_process");
	$("#home #service_searchmarketing a").attr("href", "/wp/services/#go-services_searchmarketing_process");
	$("#home #service_brandbuilding a").attr("href", "/wp/services/#go-services_brandbuilding_process");
	
	$("#services a.service_webdesign").click(function() {									  
		serviceWebdesign();
		return false;
	});
	if(jQuery.url.attr('anchor') == "go-services_webdesign_process") {
		serviceWebdesign();
	}
	
	$("#services a.service_searchmarketing").click(function() {
		serviceSearchmarketing();
		return false;
	});
	if(jQuery.url.attr('anchor') == "go-services_searchmarketing_process") {
		serviceSearchmarketing();
	}
	
	$("#services a.service_brandbuilding").click(function() {
		serviceBrandbuilding();
		return false;
	});
	if(jQuery.url.attr('anchor') == "go-services_brandbuilding_process") {
		serviceBrandbuilding();
	}
	
	$("#services a.service_webdesign").mouseover(function() {
		$("#services #service_webdesign a").toggleClass("arrow_highlight");													  
	}).mouseout(function() {
		$("#services #service_webdesign a").toggleClass("arrow_highlight");	
	});
	$("#services a.service_searchmarketing").mouseover(function() {
		$("#services #service_searchmarketing a").toggleClass("arrow_highlight");													  
	}).mouseout(function() {
		$("#services #service_searchmarketing a").toggleClass("arrow_highlight");	
	});
	$("#services a.service_brandbuilding").mouseover(function() {
		$("#services #service_brandbuilding a").toggleClass("arrow_highlight");													  
	}).mouseout(function() {
		$("#services #service_brandbuilding a").toggleClass("arrow_highlight");	
	});
	
	$("#services #services_intro_home a").click(function() {
		$("#services #service_webdesign a").removeClass("highlight");
		$("#services #service_searchmarketing a").removeClass("highlight");
		$("#services #service_brandbuilding a").removeClass("highlight");
		$("#service_indicator").stop().animate({
			"left": "-200px"
		}, 300);
		$("#services_container").stop().animate({
			"left": "0"
		}, "normal");
		return false;												 
	});
}

function serviceWebdesign() {
	$("#services #service_searchmarketing a").removeClass("highlight");
	$("#services #service_brandbuilding a").removeClass("highlight");
	$("#services #service_webdesign a").addClass("highlight");	
	$("#service_indicator").stop().animate({
		"left": "85px"
	}, 300);
	$("#services_container").stop().animate({
		"left": "-1020px"
	}, "normal");	
}

function serviceSearchmarketing() {
	$("#services #service_webdesign a").removeClass("highlight");
	$("#services #service_brandbuilding a").removeClass("highlight");
	$("#services a.service_searchmarketing").addClass("highlight");															 
	$("#service_indicator").stop().animate({
		"left": "405px"
	}, 300);
	$("#services_container").stop().animate({
		"left": "-2040px"
	}, "normal");
}

function serviceBrandbuilding() {
	$("#services #service_webdesign a").removeClass("highlight");
	$("#services #service_searchmarketing a").removeClass("highlight");
	$("#services a.service_brandbuilding").addClass("highlight");	
	$("#service_indicator").stop().animate({
		"left": "725px"
	}, 300);
	$("#services_container").stop().animate({
		"left": "-3060px"
	}, "normal");
}*/

function commentsForm() {
	$("#comment_form").validate();
}

function contactForm() {
	$("#contact_us_form").validate();	
}