// BOF GOOGLE FONT
//
WebFontConfig = {
    google: { families: [ 'PT+Sans:400,400italic,700,700italic:latin', 'Cabin::latin' ] }
};
(function() {
	var wf = document.createElement('script');
	wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
	  '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
	wf.type = 'text/javascript';
	wf.async = 'true';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(wf, s);
})();
//
// EOF GOOGLE FONT
//
//
// BOF GENERAL STUFF
//
$(window).load(function () {				   
	// SET IMG BTN ROLLOVERS
	// alert($('div.btn').size());
	$('div.btn').each(function(index) {		
		$(this).css('display', 'block');
		//
		var btn_w = $(this).find("img").width();
		var btn_h = ($(this).find("img").height())*0.5;
		//
		//alert('btn:'+btn_w+'x'+btn_h+';');
		//		
		$(this).css('width', btn_w+'px');
		$(this).css('height', btn_h+'px');
		//
		$(this).hover(function() {
			$(this).find("img").css('top', '-'+btn_h+'px');
		}, function() {
			$(this).find("img").css('top', '0px');
		});
	});
	//
	$('li.btn a').hover(function() {
		$(this).find("img").css('left', '-15px');
	}, function() {
		$(this).find("img").css('left', '0px');
	});
	//
	$('#login').hover(function() {
		$(this).css('background-position', '0px -40px');
	}, function() {
		$(this).css('background-position', '0px 0px');
	});
});
//
// INIT COLORBOX
$(document).ready(function(){
	// SET BODY WIDTH
	setBodyWidth();
	//
	// SET COLORBOX LINKS
	$("a[rel='tmb']").colorbox({current:'Photo {current} of {total}'});
	$("a[rel='tmb_sngl']").colorbox({rel:'nofollow'});
	$("a[rel='lnk']").colorbox({current:'Page {current} of {total}'});
	$("a[rel='lnk_sngl']").colorbox({rel:'nofollow', initialHeight:'400', initialWidth:'400'});
	//
	var $gallery = $('a[rel=tmb]').colorbox();
	$('a#openGallery').click(function(e){
	  e.preventDefault();
	  $gallery.eq(0).click();
	});
	//
	$('#nl_email').focus(function(){
		var eml = $(this).val();
		if(eml == 'Enter your email address here...'){
			$(this).val('');
		}
	});
	//
	$('#nl_email').blur(function(){
		var eml = $(this).val();
		if(eml == ''){
			$(this).val('Enter your email address here...');
		}
	});
	//
	var pathname = window.location.pathname;
	//
	$('#l_nav li').each(function(index) {
		var this_link = "/" + $(this).find("a").attr('href');
		if(this_link == pathname){
			$(this).addClass('curr');
		}
	});
});
//
// EOF GENERAL STUFF
//
// BOF SLIDESHOW
$(function() {
	$('#slideshow li').bind('click', function() {
		var idx = $(this).index();
		//alert(idx);
		$('#slideshow li').removeAttr('class');
		$('#slideshow li:eq('+idx+')').addClass('curr');
	});
});
// EOF SLIDESHOW
//
//
function setBodyWidth() {
	// SET BODY WIDTH IF BELOW 980
	var win_w = $(window).width();
	//
	if(win_w < 1020){
		$('body').width(1020);
	} else {
		$('body').width(win_w);	
	}
}
//
function get_val(fld){
	if($(fld).length){
		v = $(fld).val();
		return v;
	} else {
		alert('No Matching Field!\nID:'+fld);
		return false;
	}
}
//
function is_email(eml) {
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if(eml=='' || !emailReg.test(eml)) {
		return false;
	} else {
		return true;
	}
}
//
function input_err(id){
	if(id.substring(0,1) != "#"){
		var id = "#"+id;
	}
	//
	var input_fld = $(id);
	var input_nam = input_fld.parent().find('p');
	//
	input_fld.addClass('err');
	input_nam.addClass('err');
}
//
$(function() {
	$('#nl_signup').bind('click', function() {
		var eml = $('#nl_email').val();
		//
		if(is_email(eml)){
			$('#nl_email').val('Enter your email address here...');
			$(this).colorbox({
				href:'nl.php?eml='+eml,
				rel:'nofollow',
				initialHeight:'200',
				initialWidth:'200',
				escKey:false,
				overlayClose:false,
				onLoad: function() {
					$('#cboxClose').remove();
				},
				onComplete: function() {
					var c_height = $('#cboxLoadedContent').height();
					$('#cboxContent').height(c_height);
					$('#cboxLoadedContent').height(c_height);
					$('#cboxMiddleLeft').height(c_height);
					$('#cboxMiddleRight').height(c_height);
				}
			});
		} else {
			alert('Please enter a valid email address');	
		}
	});
});
//
$(function() {
	$('#frm_sub').bind('click', function() {
		var msg = '';
		var sub_form = true;
		var typ = $(this).find('p').attr('id');
		//alert(typ);
		//
		$('.err').removeClass('err');
		//
		switch(typ){
			case 'corp_acc' :
				//alert('Corporate Account');
				if(get_val('#comp_name') == ''){
					sub_form = false;
					msg += 'Enter a company name.\n';
					input_err('#comp_name');
				}
				//
				if(get_val('#contact_name') == ''){
					sub_form = false;
					msg += 'Enter a contact name.\n';
					input_err('#contact_name');
				}
				//
				if(!is_email(get_val('#contact_email'))){
					sub_form = false;
					msg += 'Enter a valid email address.\n';
					input_err('#contact_email');
				}
				//
				if(get_val('#biz_addr') == ''){
					sub_form = false;
					msg += 'Enter a business address.\n';
					input_err('#biz_addr');
				}
				//
				if(get_val('#biz_nature') == ''){
					sub_form = false;
					msg += 'Enter the nature of your business.\n';
					input_err('#biz_nature');
				}
				//
				if(get_val('#postcode') == ''){
					sub_form = false;
					msg += 'Enter a postcode.\n';
					input_err('#postcode');
				}
				//
				if(get_val('#telnum') == ''){
					sub_form = false;
					msg += 'Enter a telephone number.\n';
					input_err('#telnum');
				}
				//
				if(get_val('#faxnum') == ''){
					sub_form = false;
					msg += 'Enter a fax number.\n';
					input_err('#faxnum');
				}
				//
				if(get_val('#mobile') == ''){
					sub_form = false;
					msg += 'Enter a mobile number.\n';
					input_err('#mobile');
				}
				//
				if(get_val('#enq_reason') == ''){
					sub_form = false;
					msg += 'Enter a reason for currency requirements.\n';
					input_err('#enq_reason');
				}
				//
				if(get_val('#curr_reqs') == ''){
					sub_form = false;
					msg += 'Enter your currency requirements.\n';
					input_err('#curr_reqs');
				}
				//
			break;
			//
			case 'priv_acc' :
				//alert('Corporate Account');
				if(get_val('#name_first') == ''){
					sub_form = false;
					msg += 'Enter a first name.\n';
					input_err('#name_first');
				}
				//
				if(get_val('#name_last') == ''){
					sub_form = false;
					msg += 'Enter a last name.\n';
					input_err('#name_last');
				}
				//
				if(!is_email(get_val('#email'))){
					sub_form = false;
					msg += 'Enter a valid email address.\n';
					input_err('#email');
				}
				//
				if(get_val('#telnum') == '' && get_val('#mobile') == ''){
					sub_form = false;
					msg += 'Enter at least one contact number.\n';
					input_err('#telnum');
					input_err('#mobile');
				}
				//
			break;
			//
			case 'gen_enq' :
				//alert('Corporate Account');
				if(get_val('#name_first') == ''){
					sub_form = false;
					msg += 'Enter a first name.\n';
					input_err('#name_first');
				}
				//
				if(get_val('#name_last') == ''){
					sub_form = false;
					msg += 'Enter a last name.\n';
					input_err('#name_last');
				}
				//
				if(!is_email(get_val('#email'))){
					sub_form = false;
					msg += 'Enter a valid email address.\n';
					input_err('#email');
				}
				//
				if(get_val('#telnum') == '' && get_val('#mobile') == ''){
					sub_form = false;
					msg += 'Enter at least one contact number.\n';
					input_err('#telnum');
					input_err('#mobile');
				}
				//
			break;
		}
		//
		if (!sub_form) {
			//alert(msg);
			return false;
		} else {
			//alert('Success');
			$("div.enq_form").wrap('<form id="enq_info" />');
			$('#enq_info').attr('action', 'mailers/'+typ+'.php');
			$('#enq_info').attr('method', 'post');
			$('#enq_info').submit();
			return true;
		}
	});
});

