//Master Javascript file
//version:   4.0
//website:   http://www.headscape.co.uk

// Loads up the various functions we are going to use
$(document).ready(function () {
	addCufon();
	jsEnabled();
	newwindow();
	addCorners();
	addOverlay();
	addOverlaySmall();
	bigTextImage();
	conditionalFormElements();
});

function addCufon() {
	Cufon.replace('#rightColumn h2');
	if ($("body").attr("class").indexOf("bullBreeds") == -1)
	{
		Cufon.replace('#tripticList p');
	}
	Cufon.replace('.featureList');
	Cufon.replace('.featureDetails h3');
	Cufon.replace('.featureDetails h4 a');
	Cufon.replace('#facebook .moreActions');
}

function addCorners() {
	$("p.addCorners").wrapInner('<span class="TR"><span class="BL"><span class="BR"></span></span></span>');
};

function newwindow() {
	$(".email a").click(function(){
			window.open (this.href, "mywindow","resizable=1,width=550,height=450"); 	
			return false;
	});
};

// Adds a class to the body tag so any elements on the page can be styled differently if the browser supports JS
function jsEnabled(i) { 
	$("body").addClass("jsEnabled");
}

//Lighbox function
function lighbox(i) {
    $('.box a').lightBox();
}

function addOverlay (i) {
	$(".overlayCurve").wrap('<span class="curvedImage"></span>');
	$(".curvedImage").append('<span class="curveBr">&nbsp;</span>');
}

//Creates the curved corners
function addOverlaySmall(i) {
	$(".overlayCurveSmall").wrap('<span class="curvedImageSmall"></span>')
	$(".curvedImageSmall").append('<span class="curveBrSmall">&nbsp;</span>');
}

//Creates the curved corners
function bigTextImage(i) {
	$(".bigTextImage").wrap('<div class="curvedBL"></div>') 
	$(".bigTextImage").before('<span class="curveTR">&nbsp;</span>') 
	$(".bigTextImage").after('<span class="curveBL">&nbsp;</span>') 
}

function conditionalFormElements() {
	var conditionalChanged = function () {
		$(this).each(function () {
			var name = $(this).attr('name');
			if ($(this).attr('data-on') != undefined)
				$('#' + $(this).attr('data-for')).toggle($('input[name=' + name + ']:checked, select[name=' + name + ']').val() == $(this).attr('data-on'));
			else
				$('#' + $(this).attr('data-for')).toggle(!($('input[name=' + name + ']:checked, select[name=' + name + ']').val() == $(this).attr('data-off')));
		});
	};
	$('.conditional').change(conditionalChanged);
	conditionalChanged.apply($('.conditional'));
}




