$(function(){
    //Get our elements for faster access and set overlay width
    var div = $('div.sc_menu'),
                 ul = $('ul.sc_menu'),
                 // unordered list's left margin
                 ulPadding = 15;

    //Get menu width
    var divWidth = div.width();

    //Remove scrollbars
    div.css({overflow: 'hidden'});

    //Find last image container
    var lastLi = ul.find('li:last-child');

    //When user move mouse over menu
    div.mousemove(function(e){

      //As images are loaded ul width increases,
      //so we recalculate it each time
      var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;

      var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
      div.scrollLeft(left);
    });
});

$(document).ready(function(){
	//replace headers with images
	$(".widget-title").each(function() {
		var widgettitle=$(this).html();
		switch (widgettitle) {
			case "Recent Posts Sidebar":
				$(this).html("<br/><br/><br/><img src=\"wp-content/themes/ptom/images/posts.jpg\" width=\"96\" height=\"24\" alr=\"Recent Posts\"/>");
			break;
			case "Recent Comments Sidebar":
				$(this).html("<br/><br/><img src=\"wp-content/themes/ptom/images/comments.jpg\" width=\"168\" height=\"24\" alr=\"Recent Comments\"/>");
			break;
			case "Search Sidebar":
				$(this).html("<br/><br/><img src=\"wp-content/themes/ptom/images/search.jpg\" width=\"118\" height=\"24\" alr=\"Search\"/>");
			break;
		}
	});
	
	$("#searchsubmit").attr("value","");
	$(".screen-reader-text").replaceWith("");
	$("#reply-title").html("<br/><img src=\"wp-content/themes/ptom/images/reply.jpg\" width=\"225\" height=\"24\" alt=\"Reply\"/><br/><br/>");
	$(".required").html("");
	$(".comment-notes").html("");
	$(".form-allowed-tags").html("");
	$(".required").removeClass("required");
	$("#submit").attr("value","");
	$(".comment-form-author label:first-child").html("<img src=\"wp-content/themes/ptom/images/form/name.jpg\" width=\"150\" height=\"24\" alt=\"Reply\" class=\"formelement\"/>");
	$(".comment-form-email label:first-child").html("<img src=\"wp-content/themes/ptom/images/form/email.jpg\" width=\"150\" height=\"24\" alt=\"Reply\" class=\"formelement\"/>");
	$(".comment-form-url label:first-child").html("<img src=\"wp-content/themes/ptom/images/form/website.jpg\" width=\"150\" height=\"24\" alt=\"Reply\" class=\"formelement\"/>");
	$(".comment-form-comment label:first-child").html("<img src=\"wp-content/themes/ptom/images/form/comment.jpg\" width=\"150\" height=\"24\" alt=\"Reply\" /><br/>");
	$("#author").addClass("required");
	$("#email").addClass("required email");
	$("#comment").addClass("required");
	
	$("#commentform").validate();
	
	$(".menu_spacer").hover(function() {
		var spacer="#"+$(this).attr("id");
		if (spacer!="") {
			spacer+="t";
			$(spacer).addClass("orange");
		}
	}, function() {
		var spacer="#"+$(this).attr("id");
		if (spacer!="") {
			spacer+="t";
			$(spacer).removeClass("orange");
		}
	});
	
	$(".menu_text").hover(function() {
		$(this).addClass("orange");
	}, function() {
		$(this).removeClass("orange");
	});
	
	$(".tab_button").hover(function() {
		$(this).css('backgroundPosition', '0px 64px');
	}, function() {
		$(this).css('backgroundPosition', '0px 0px');
	});
	
	//video page
	 $(".youtube_pic").hover(function() {
		$("#video_title").html($(this).attr("alt"));
	}, function () {
		$("#video_title").html($("#secret_name").val());
	});
	
	$(".youtube_pic").click(function() {
		var vid=$(this).attr("id");
		$("#secret_name").val($(this).attr("alt"));
		$("#video_title").html($(this).attr("alt"));
		$("#vid_container").html('<object width="590" height="467"><param name="movie" value="http://www.youtube.com/v/'+vid+'?fs=1&amp;hl=en_GB&amp;rel=0&amp;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+vid+'?fs=1&amp;hl=en_GB&amp;rel=0&amp;hd=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="590" height="467"></embed></object>')
	});
})
