jQuery(function ($) {
	// for IE
	$('#access ul.menu li.current-menu-parent > a, #access ul.menu li.current-menu-item > a, body.about-us #access ul.menu li#menu-item-59 > a, body.single-works #access ul.menu li#menu-item-65 > a, body.press-releases #access ul.menu li#menu-item-67 > a').css('color', '#522f19');
	
	// video tab control
	$('.video-thumbs a').click(function(){
		switch_tabs($(this));
	});
 
	switch_tabs($('.defaulttab'));
	
	// video tab control
	function switch_tabs(obj) {
		$('.video-content').hide();
		
		$('.video-thumbs a').removeClass("selected");
		var id = obj.attr("rel");
	 
		$('#'+id).show();
		obj.addClass("selected");
	}
	
	// work
	
	var original_h2 = new Array();
	var filtered_h2 = new Array();
	
	$("body.work .grid .work-content").each(function(i) {
		original_h2[i] = $(this).find("h2").html();
		filtered_h2[i] = original_h2[i].replace("//", "<br />");
	});
	
	
	function grid_func() {
		$("body.work .grid .work-content").each(function(i) {
			$(this).find("h2").html(filtered_h2[i]);
		});
		
		$("body.work #content .works div.work-content").css({"display": "none"});
	}
	
	function list_func() {
		$("body.work .list .work-content").each(function(i) {
			$(this).find("h2").html(original_h2[i]);
		});
		
		$("body.work #content .works div.work-content").css({"display": "block"});
	}
	
	grid_func();
	enable_grid_hover();
	
	
	// work grid list switcher
	$("ul.layout-switcher li.grid").click(function() {
		$("#container").removeClass("grid list").addClass("grid");
		grid_func();
		
		enable_grid_hover();
		
	});
	
	$("ul.layout-switcher li.list").click(function() {
		$("#container").removeClass("grid list").addClass("list");
		list_func();
		
		enable_list_hover();
		
		$("body.work .grid #content .works").die("mouseover mouseout");
	});
	
	
	// grid hover
	function enable_grid_hover() {
		
		$('.block').remove();
		
		$("body.work .grid #content .works").live("mouseover mouseout", function(event) {
			
			if (event.type == 'mouseover') {
				$(this).find("div.work-content").css({"display": "block", "cursor": "pointer"});
			} else {
				$(this).find("div.work-content").css({"display": "none", "cursor": "default"});
			}
		});
	};
	
	
	function enable_list_hover() {
		$("body.work .list #content .works").each(function(i) {
			$(this).append("<div class=\"block\"></div>");
		});
		
		$("body.work .list #content .works").live("mouseover mouseout", function(event) {
			
			if (event.type == 'mouseover') {
				$(this).css({"cursor": "pointer"});
				$(this).find("div.block").css({"display": "block"});
			} else {
				$(this).css({"cursor": "default"});
				$(this).find("div.block").css({"display": "none"});
			}
		});
		
		test();
	};
	
	$("body.work .grid #content .works div.work-content").each(function(i) {
		
		var url = $(this).prev().find("a").attr("href");
		
		$(this).click(function() {
			 window.location = url;
		});
		
	});
	
	function test() {
		$("body.work .list #content .works .block").each(function(i) {
			
			var url = $(this).prev().prev().find("a").attr("href");
			
			$(this).click(function() {
				 window.location = url;
			});
			
		});
	}
	
	// work-single
	
	/* edit img wrapped by p */
	$("body.single-works div.entry-content p:has(img)").css('padding' , '0');
	
	// everything scottish home
	$("body.page-template-tpl-everything-scottish-home-php #content .entry-content ul li").css({"cursor": "pointer"});
	
	$("body.page-template-tpl-everything-scottish-home-php #content .entry-content ul li").click(function(){
    	window.location=$(this).find("a").attr("href");
    	return false;
	});
	
	$("body.page-template-tpl-everything-scottish-home-php #content .entry-content ul li").hover(
		function () {
			$(this).css({"background-position": "bottom center"});
	  	},
	  	function () {
			$(this).css({"background-position": "top center"});
	  	}
	);
	
	
	// comment form
	$("#commentform span.required").css("display", "none");
	$("#commentform p.comment-form-author label, #commentform p.comment-form-email label").append('<span class="required">*</span>');

	$("#commentform p.comment-form-url input[type='text'], #commentform textarea").focus(function() {
		if($(this).val() == '') {
            $(this).prev('label').stop().animate({ opacity: 0.4 }, 200);
        }
	}).blur(function() {
        if($(this).val() == '') {
            $(this).prev('label').stop().animate({ opacity: 1 }, 200);
        }
    }).keydown(function() {
        if($(this).css('opacity')) {
            $(this).prev('label').stop().animate({ opacity: 0 }, 200);
        }
    });
	
	$("#commentform p.comment-form-author input[type='text'], #commentform p.comment-form-email input[type='text']").focus(function() {
		if($(this).val() == '') {
            $(this).prev().prev('label').stop().animate({ opacity: 0.4 }, 200);
        }
	}).blur(function() {
        if($(this).val() == '') {
            $(this).prev().prev('label').stop().animate({ opacity: 1 }, 200);
        }
    }).keydown(function() {
        if($(this).css('opacity')) {
            $(this).prev('label').stop().animate({ opacity: 0 }, 200);
        }
    });
	

});
