$(function(){
	$('h1,h2,h3').not('#pagetitle,.noDecoration').headerBar();
	windowScroll();
	stickyFooter();
	inputFodder();
	placeholderFix();
	logoClicker();
});

$(window).load(function(){
	$('img,#flash_object').not('.socialmedia-buttons img,#p165 #content img').imgFrame();
	navAnimation();
});

function windowScroll(){
	newScroll();
	$(window).resize(newScroll);
	function newScroll(){
		ww = $(window).width();
		if(ww>=1000){
			$('html').css('overflow-x','hidden');
		}
		if(ww<1000){
			$('html').css('overflow-x','visible');
		}
	}
}

function navAnimation() {
	$('#leather-patch').animate({'right':0},700);
}

function stickyFooter(){
	pt = parseInt($('#footer').css('paddingTop')),
	pb = parseInt($('#footer').css('paddingBottom')),
	fp = pt+pb,
	fh = $('#footer').height()+fp;
	$('#rap').css('marginBottom',-fh+'px');
	$('<div id="push"/>').appendTo('#rap').height(fh);
}

function inputFodder(){
	$('input[type="text"],textarea').addClass('input');
	$('input[type="submit"]').addClass('submit');
	$('input[name*="filter_"]').hide();
}

function placeholderFix(){
	$('.input').each(function(){
		var ph = $(this).attr('placeholder');
		v = $(this).val();
		if(v.length < 1) {
			$(this).val(ph);
		}
		$(this).css('color','#DADADA');
		$(this).focus(function(){
			$(this).css('color','#000');
			if($(this).val() == ph){
				$(this).val('');
			}
		}).blur(function(){
			if(this.value=='') {
				$(this).val(ph).css('color','#DADADA');
			}
		});
	});
}

jQuery.fn.headerBar = function() {
	return this.each(function(){
		if ($('a', this).length == 0) {
			textreset = $(this).text();
			$(this).html(textreset);
		}
		left = '<div class="headleft"></div>';
		right= '<div class="headright"></div>';
		$(this).wrap('<div class="title-wrap"/>').parent().prepend(left).append(right).css({
			'width':'100%',
			'height':'47px'
		});
		$('.headleft').css({
			'float':'left',
			'width':'35px',
			'height':'47px',
			'background':'url(/wp-content/themes/horsies/images/heading-left.png)'
		});
		$(this).css({
			'float':'left',
			'height':'47px',
			'background':'url(/wp-content/themes/horsies/images/heading-middle.png)',
			'lineHeight':'47px',
			'overflow':'hidden',
			'maxWidth':$(this).parent().width()-69+'px'
		});
		$('.headright').css({
			'float':'left',
			'width':'34px',
			'height':'47px',
			'background':'url(/wp-content/themes/horsies/images/heading-right.png)'
		});
	});
};

jQuery.fn.imgFrame = function() {
	return this.each(function(){
		w = $(this).outerWidth();
		h = $(this).outerHeight();
		c = $(this).attr('class');
		i = '<div class="shadow"></div>';
		$(this).wrap('<div/>').parent().height(h).width(w).css({
			'background':'url(/wp-content/themes/horsies/images/img-frame.png)',
			'position':'relative',
			'borderRadius':'3px',
			'-moz-border-radius':'3px'
		}).attr('class',c).append(i);
		$(this).height(h*0.8).width(w*0.8).removeAttr('class').removeAttr('height').removeAttr('width').css({
			'position':'absolute',
			'top':'50%',
			'left':'50%',
			'marginLeft':-(w*0.8)/2+'px',
			'marginTop':-(h*0.8)/2+'px',
			'border':'1px solid #882906'
		});
	});
};

function logoClicker() {
	$('#logo').click(function(){
		window.location.href = '/biglogo';
	}).css('cursor','pointer');
}
