jQuery(document).ready(function ($) {

	$(".vidlink").click(function(){
		$("#lbbg, #lbin").each(function() {$(this).fadeIn("slow");});
		return false;
	});
	$("#lbbg, #lbin").click(function(){
		$("#lbbg, #lbin").each(function() {$(this).fadeOut("slow");});
		return false;
	});
	
	$('.hpblogdivheadtabtop').click(function(){
		$('.hpblogdivheadtabtop.current').removeClass('current');
		$(this).addClass('current');
		var index = $(".hpblogdivheadtabtop").index(this);
		$('.hpblogtabinner.current').fadeOut("fast").removeClass('current');
		$('.hpblogtabinner').eq(index).fadeIn("fast").addClass('current');
		
	});
	
	$('.proddivheaderbtn, .appinfoheaderbtn').click(function(){
		if ($(this).parent().next().is(":visible")){
			$(this).parent().next().slideUp();
			$(this).parent().css('background-position', '0 0');
		}
		else {
			$(this).parent().next().slideDown();
			$(this).parent().css('background-position', '0 -88px');
		}
		return false;
	});
	
	
	$('.oestableshowall').click(function(){
		if ($(this).hasClass('hider')){
			$('.oestable.hide').slideUp("slow");
			$(this).removeClass('hider').html('Show all product tables');
		}
		else {
			$('.oestable.hide').slideDown("slow");
			$(this).addClass('hider').html('Hide extra product tables');
		}
		return false;
	});
	
	$("#subc").focus(function () {if (this.value == this.defaultValue) {this.value = ""}}).blur(function () {if (!this.value.length) {this.value = this.defaultValue;$(this).css("color","#5d80a3");}});

	$("#subcsub").click(function() {
		var errors = false;
		$("#subc").each(function () {
			if (this.value == this.defaultValue) {
				errors = true; 
				$("#subc").css("color","red").focus(); 
			}
			var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
			var email = $("#subc").val();
			if (!pattern.test(email)){
				errors = true;
				$("#subc").css("color","red").focus();
			}
		});
		
		if (errors) {return false}
		
		$.post("http://www.oestechnologies.com/wp-content/themes/oes/ajax.subscribe.php", {
            "ctemail": $("#subc").val()
        }, function (data) {
            if (data.response == "Thank You") {
                $("#subc").val("Thank you for subscribing to us!").css("color","green");
            } else {
                alert(data.response)
            }
        }, "json");
		return false;
	});

	$(".deleter").click(function() {	
		var answer = confirm ("Are you sure you want to delete this item?");
		if (!answer)
			return false;
	});
	
});
