/*<![CDATA[*/
/*****************************************************************************
//-> START General Functions
*****************************************************************************/

// --> FORM pre-submit callback
function showRequest(formData, jqForm, options) {

	var form = jqForm[0];

	if (!form.name.value) {

		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='/images/attention.png' width='11' height='11' alt='' /> Please fill in your name.");
		form.name.focus();

		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});

		return false;
	}

	if (!echeck(form.email.value)) {
		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='/images/attention.png' width='11' height='11' alt='' /> Please fill in a valid email address.");
		form.email.focus();

		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});

		return false;
	}


	if (!form.comments.value) {

		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='/images/attention.png' width='11' height='11' alt='' /> Please fill in the content of your message.");
		form.comments.focus();

		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});

		return false;
	}

	if (!verify(form.verify.value)) {

		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='/images/attention.png' width='11' height='11' alt='' /> Please answer the question, we need to check that you'r human...");
		form.verify.focus();

		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});

		return false;
	}

	$('.msg').fadeIn(500).html("<img src='/images/loadinfo.gif' width='16' height='16' alt='' /> Please wait, processing form...");
	$('#contactform').slideUp();

}


// --> post-submit callback
function showResponse()  {
	$('.msg').fadeIn(500).html("<img class='png_bg' src='/images/success.png' width='16' height='16' alt='' /> <strong>Message Sent Successfully!<\/strong><br \/>Thank you, we will get back to you as fast as we can.");
	$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});

}

// --> removing the status message with a 5sec timer activated
function removeMsg() {
	$('.msg').oneTime(4000,function() {
		$(this).slideUp(500);
		//console.debug($('.msg').oneTime());
	});
}

// --> Email Validation function
function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   //alert("Invalid E-mail ID")
		return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail ID")
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail ID")
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		//alert("Invalid E-mail ID")
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("Invalid E-mail ID")
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		//alert("Invalid E-mail ID")
		return false;
	 }

	 if (str.indexOf(" ")!=-1){
		//alert("Invalid E-mail ID")
		return false;
	 }
	 return true;
}

// --> START CAPTCHA
var flag = false;
var a = Math.ceil(Math.random() * 10);
var b = Math.ceil(Math.random() * 10);

function verify(){

	if(!flag){
		var c = a + b;
		var d = $("#verify:input").val();

		//$("label.verify").html("What is "+ a + " + " + b +"? ");
		$('label.verify').append("What is "+ a + " + " + b +"? ");
		flag = true;
		return false;
	}

	var c = parseInt($("#aVal:input").val()) + parseInt($("#bVal:input").val());
	var d = $("#verify:input").val();

	if (flag && c == d) {
		return true;
	}else{
		return false;
	}
	return false;
}

/*****************************************************************************
//-> END General Functions
*****************************************************************************/

/*****************************************************************************
//-> START SlideMenu
*****************************************************************************/
//Specify full URL to down and right arrow images (23 is padding-right to add to top level LIs with drop downs):
var arrowimages={down:['downarrowclass', 'images/down.gif', 23], right:['rightarrowclass', 'images/left.gif']}

var jqueryslidemenu={

animateduration: {over: 200, out: 100}, //duration of slide in/ out animation, in milliseconds

buildmenu:function(menuid, arrowsvar){
	$(document).ready(function($){
		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			$curobj.children("a:eq(0)").css(this.istopheader? {paddingLeft: arrowsvar.down[2]} : {}).append(
				'<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
				+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
				+ '" style="border:0;" />'
			)
			$curobj.hover(
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					this._offsets={right:$(this).offset().right, top:$(this).offset().top}
					var menuleft=this.istopheader? 0 : this._dimensions.w
					menuleft=(this._offsets.right+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					if ($targetul.queue().length<=1) //if 1 or less queued animations
						$targetul.css({right:menuleft+"px", width:this._dimensions.subulw+'px'}).slideDown(jqueryslidemenu.animateduration.over)
				},
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					$targetul.slideUp(jqueryslidemenu.animateduration.out)
				}
			) //end hover
		}) //end $headers.each()
		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
	}) //end document.ready
}
}

//build menu with ID="menu" on page:
jqueryslidemenu.buildmenu("menu", arrowimages)
/*****************************************************************************
//-> END SlideMenu
*****************************************************************************/

/*****************************************************************************
//-> START Window Load
*****************************************************************************/

$(window).load(function () {

	$("a[rel*='image']").fancybox({
		'titleShow' : false,
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'easingIn' : 'easeOutBack',
		'overlayOpacity' : 0.0,
		'easingOut' : 'easeInBack'
	});

	// --> Disable filter property because of IE opacity bug
	if($.browser.name == "msie"){
		//$('#fancybox-wrap, #fancybox-overlay').css({"filter":"none"});
	}
	// --> END Disable
// --> Start insert menu seperators
	$(".jqueryslidemenu ul li.main:not(:last)").each(function(){
		$(this).after('<li><img src="images/menu-sep.gif" width="2" height="24" alt="" /></li>');
	});

// --> Start H1 replacment
	$("h1.heading").each(function(){
		var att = $(this).attr("class");
		//console.log(att);
		$(this).replaceWith('<div class="title-holder"><div class="bg-right"></div><div class="bg-mid"><h1 class="'+att+'">' + $(this).html() + '</h1></div><div class="bg-left"></div></div>');
	});

// --> Start H2 replacment
	$("h2.heading").each(function(){
		var att = $(this).attr("class");
		//console.log(att);
		$(this).replaceWith('<div class="title2-holder"><div class="bg2-right"></div><div class="bg2-mid"><h2 class="'+att+'">' + $(this).html() + '</h2></div><div class="bg2-left"></div></div>');
	});

// --> Start Disable '#' links from being clicked
	$("a[href^='#']").click(function() {
		return false;
	});

// --> Init External Links
	$("a[rel*='external']").attr("target","_blank");

// --> Init SPAM Email links
	$("a[href^='mailto:']").each(function(){
		var mail = $(this).attr("href").replace("mailto:","");
		var replaced = mail.replace("/at/","@");
		$(this).attr("href","mailto:"+replaced);
		if($(this).text() == mail){
			$(this).text(replaced);
		}
	});

});

/*****************************************************************************
//-> END Window Load
*****************************************************************************/

/*]]>*/

//============================================
//============= shareOnFacebook ==============
//============================================
function shareOnFacebook() {
	url = location.href;
	title = document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

