// v1.0


if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
var viewportmeta = document.querySelectorAll('meta[name="viewport"]')[0];
if (viewportmeta) {
viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0';
document.body.addEventListener('gesturestart', function() {
viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
}, false);
}
}

/* jQuery Nivo Slider for image rotator on the Home page */
$.getScript('js/mylibs/jquery.nivo.slider.pack.js', function() {
	$('#slider').nivoSlider({controlNav: false, pauseTime: 6000, captionOpacity: 1.0});
});

// Initialise Superfish

$('ul.sf-menu').supersubs({
	minWidth:    12,   // minimum width of sub-menus in em units 
	maxWidth:    27,   // maximum width of sub-menus in em units 
	extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
	                   // due to slight rounding differences and font-family
}).superfish();		   // call supersubs first, then superfish, so that subs are 
					   // not display:none when measuring. Call before initialising 
					   // containing tabs for same reason.

// light email sign up form validation
$('#emailsignupform input[type=submit]').click(function(e) {
	if ($('#signupaddress').val() == '' || $('#signupname').val() == '' || $('#signupaddress').val() == 'Email Address' || $('#signupname').val() == 'Your Name') {
		alert('Please enter your email address and name to sign up.');
		e.preventDefault();	
	} else {
		
	}
	$('#emailsignupform').append('<input type="hidden" name="timestamp" id="timestamp" value="'+new Date()+'" />');
});

// Remove JavaScript Warning
$('.warning').remove();
$.get("inc/token.asp",function(txt) {
$("#contact").append('<input type="hidden" name="timestamp" id="timestamp" value="'+txt+'" />').attr("action","contact.asp");
});

//ie menu hover fix
if (window.attachEvent) {$("#nav li").hover(
	function(){$(this).addClass("iehover");},
	function(){$(this).removeClass("iehover");}
);};

//email functions
$(".sendmail").each(function(i) {
	//	username+domain+com+[display}
	var a = $(this).text().split("+");
	a[3] = a[3] || a[0]+"@"+a[1]+"."+a[2];
	$(this).text("").after('<a class="email" href="mailto:'+a[0]+'@'+a[1]+'.'+a[2]+'">'+a[3]+'</a>').remove();
});

//show hide div
$("div[id^='shd']").each(function(i) {$(this).hide();});
$("a[id^='shd']").click(function(){
	var id = $(this).attr("id");
	id = id + "d";
	$("div[id^='shd']").not("#"+id).hide("fast");
	$("#"+id).show("fast");
	return false;
});
//toggle div
$("div[id^='tog']").each(function(i) {$(this).hide();});
$("a[id^='tog']").click(function(){
	var id = $(this).attr("id");
	id = id + "d";
	$("#"+id).toggle("fast");
	return false;
});
//flash movies
$("div.flashmov").each(function(i){
	// url+w+h
	var a = $(this).text().split("+"); 
	var str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+a[1]+'" height="'+a[2]+'"><param name="movie" value="'+a[0]+'"> <param name="quality" value="high"><param name="wmode" value="transparent"><embed src="'+a[0]+'" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+a[1]+'" height="'+a[2]+'"></embed></object>';
		$(this).html(str);
});
	
// FLV+SWF+SKIN+w+h+ID
$("div.flashvid").each(function(i){
	var a = $(this).text().split("+"); 
	var str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+a[3]+'" height="'+a[4]+'" id="'+a[5]+'"><param name="movie" value="'+a[1]+'" /><param name="salign" value="lt" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="FlashVars" value="&MM_ComponentVersion=1&skinName='+a[2]+'&streamName='+a[0]+'&autoPlay=true&autoRewind=false" /><embed src="'+a[1]+'" flashvars="&MM_ComponentVersion=1&skinName='+a[2]+'&streamName='+a[0]+'&autoPlay=true&autoRewind=false" quality="high" scale="noscale" width="'+a[3]+'" height="'+a[4]+'" name="'+a[5]+'" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" /></object>';
	$(this).html(str);
});

$("img.flashvidpic").click(function(){
	var id = "#" + $(this).attr("id") + "d";
	$(this).addClass("hide");
	$(id).removeClass("hide");
});

// no label forms, with minimal no label validation
$("form.nolabel label").each(function(i){
	if ($(this).attr("type") !== "radio" && $(this).attr("type") !== "checkbox") {
		if ($("#"+$(this).attr("for")).val() !== null) {$(this).css({'top':'-1000px','left':'-1000px'});}
		var that = $(this).hide().css("cursor","text");
		var pos = $("#"+$(this).attr("for")).offset();
		pos.left += 5;
		$(this).css({'position':'absolute','z-index':'30','top':pos.top+'px','left':pos.left+'px','color':'#000000;'}).show();
		$("#"+$(this).attr("for")).focus(function(){
			$(that).css({'top':'-1000px','left':'-1000px'});
		}).blur(function(){
			if ($(this).val() === "") {$(that).css({'top':pos.top+'px','left':pos.left+'px'});}
		});
	}
});

//clear & replace text
$("input.crt").each(function(){
	if ($(this).val()==="") {$(this).val($(this).attr("title"));}
}).focus(function(){
	if ($(this).attr("title")===$(this).val()) {$(this).val("");}
	else {$(this).val($(this).attr("title"));}
}).blur(function(){
	if ($(this).val()==="") {$(this).val($(this).attr("title"));}
});

// Back to top scroll animation
$("a[href^=#]").click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
		var $target = $(this.hash);
		$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
		if ($target.length) {
			var targetOffset = $target.offset().top;
			var distance = Math.abs($(this).offset().top - targetOffset);
			$('html,body').animate({scrollTop: targetOffset}, 1000 + (distance / 5));
			return false;
		}
	} 
});

// Open PDF in a new tab 
$("a[href$='.pdf'],a[href$='.doc']").attr('target','_blank');

// Prevent PDF from caching
//$('a[href$=".pdf"]').each(function() { $(this).attr('href', $(this).attr('href') + (+new Date)); });

// Delete function for admin
var AdminDelete = function(id,title,folder) {
	var msg = "Are you sure you wish do delete the item named '"+title+"'? This action cannot be undone.";
	if (confirm(msg)) {window.location = "/admin/"+folder+"/Delete.asp?ID="+id;}
};


