/*<![CDATA[*/
/*****************************************************************************
//-> 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){
	jQuery(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? {paddingRight: 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-holder", arrowimages)
/*****************************************************************************
//-> END SlideMenu
*****************************************************************************/

/*****************************************************************************
//-> START General Functions
*****************************************************************************/

// --> FORM pre-submit callback
function showRequest(formData, jqForm, options) {

	var form = jqForm[0];

	if (!form.fname.value) {

		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='images/attention.png' width='11' height='11' alt='' /> Please fill in your first name.");
		form.fname.focus();

		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});

		return false;
	}

	if (!form.lname.value) {

		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='images/attention.png' width='11' height='11' alt='' /> Please fill in your last name.");
		form.lname.focus();

		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
		//$('#contactform #submit').attr('disabled','');

		return false;
	}

	if (!form.company.value) {

		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='images/attention.png' width='11' height='11' alt='' /> Please fill in company name.");
		form.company.focus();

		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
		//$('#contactform #submit').attr('disabled','');

		return false;
	}

	if (!form.country.value) {

		$('.msg').slideDown(500, removeMsg).html("<img class='png_bg' src='images/attention.png' width='11' height='11' alt='' /> Please fill in country name.");
		form.country.focus();

		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
		//$('#contactform #submit').attr('disabled','');

		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()});
		//$('#contactform #submit').attr('disabled','');

		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 - For anti spam purposes.");
		form.verify.focus();

		$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
		//$('#contactform #submit').attr('disabled','');

		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()});
	//$('#contactform #submit').attr('disabled','');

}

// --> removing the status message with a 5sec timer activated
function removeMsg() {
	$('.msg').oneTime(4000,function() {
		$(this).slideUp(500,function(){$(this).remove()});
		//.fadeOut('slow',function(){$(this).remove()});
		//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 Window Load
*****************************************************************************/

$(window).load(function () {

// --> START CONTACT FORM
	var options = {
		url:			"email.asp",
		beforeSubmit:  showRequest,  // pre-submit callback
		success:       showResponse,  // post-submit callback
		clearForm: true,        // clear all form fields after successful submit
		resetForm: true        // reset the form after successful submit
	};

	$('#contactform').submit(function() {
		$(this).find("input#submit").after('<img src="images/ajax-loader.gif" class="loader" />')

		// --> replacing the "enter" with "<br />" on the textarea
		var txtStr = document.getElementById("comments").value;
		document.getElementById("comments").value = txtStr.replace(/\n/gi, "<br />");


		$(this).ajaxSubmit(options);
		 return false;
	});

// --> Init CAPTCHA
	$('#contactform').find("fieldset").append('<input type="hidden" name="aVal" id="aVal" value="" /><input type="hidden" name="bVal" id="bVal" value="" />');
	$("#aVal:input").val(a);
	$("#bVal:input").val(b);

	verify()

// --> init Top menu Animation
	$('ul#menu li:not(.selected)')
	.css({backgroundPosition: "0 50px"})
	.mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 25px)"},
			{duration:170})
	})
	.mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 50px)"},
			{duration:170})
	})

// --> Start insert menu seperators
	$("#header ul#menu li.main:not(:last)").each(function(){
		$(this).after('<li class="sep"><img src="images/menu-sep.gif" width="11" height="25" alt="" /></li>');
	});

// --> Start replace external links
	$("a.external").each(function(){
		$(this).attr("rel","external");
	});

// --> init Image Slider
    $(".slider").jCarouselLite({
        btnNext: ".prev",
        btnPrev: ".next",
		visible: 1,
        auto: 3600,
        speed: 1000,
		easing: "easeOutCubic"
    });

// --> 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
*****************************************************************************/

/*]]>*/

