function init(){

/*
$(".button").click(function(){
		$(this).blur();
	});
	// apply input focus hack for IE
	$("a.button").mousedown(function(event){
		$(this).addClass("buttonActive");
	});
	$("a.button").blur(function(){
		$(this).removeClass("buttonActive");
	});
	$("a.button").mouseleave(function(){
		$(this).removeClass("buttonActive");
	});
	
	*/
	
	//check for and fix ipad display
	if ( checkUserAgent('iPad') ) {
    	//$("div#quick-bar").hide();
		
	}
	
	//image captions
	
	$('img.captify').captify({
		// speed of the mouseover effect
		speedOver: 'fast',
		// speed of the mouseout effect
		speedOut: 'normal',
		// how long to delay the hiding of the caption after mouseout (ms)
		hideDelay: 500,	
		// 'fade', 'slide', 'always-on'
		animation: 'slide',		
		// text/html to be placed at the beginning of every caption
		prefix: '',		
		// opacity of the caption on mouse over
		opacity: '0.7',					
		// the name of the CSS class to apply to the caption box
		className: 'caption-bottom',	
		// position of the caption (top or bottom)
		position: 'bottom',
		// caption span % of the image
		spanWidth: '100%'
	});
	
	
	$("#sinterest-submit").bind('click', function(){
			$("#register-an-interest-form").submit();									  
	});
	$("#squestion-submit").bind('click', function(){
			$("#service-question").submit();									  
	});
	
	//register an interest form - service page
	$("#register-an-interest-form").bind('submit', function(){
			//validate input
			if (!(validateInterestForm())) return false;
			return true;										   
	});
	
	//ask a question form - service page
	$("#service-question").bind('submit', function(){
			//validate input
			if (!(validateQuestionForm())) return false;
			return true;										   
	});
	
	var errstr;
	function validateQuestionForm(){
		//validate service ask a question form
		errstr = "";
		if ($("#q_cname").val() == "") errstr += "Please enter your name.\r\n"
		if ($("#q_email").val() == "") errstr += "Please enter your email address.\r\n"
		else if (!(echeck($("#q_email").val())))errstr += "Please enter a valid email address\r\n";	
		if ($("#q_squestion").val() == "") errstr += "Please enter your question.\r\n"
		
		if (errstr != "") {
			alert(errstr);
			return false;
		} else {
			return true;
		}
		
	}
	function validateInterestForm(){
		
		//validate service ask a question form
		 errstr = "";
		if ($("#i_cname").val() == "") errstr += "Please enter your name.\r\n"
		if ($("#i_email").val() == "") errstr += "Please enter your email address.\r\n"
		else if (!(echeck($("#i_email").val())))errstr += "Please enter a valid email address\r\n";	
		
		
		if (errstr != "") {
			alert(errstr);
			return false;
		} else {
			return true;
		}
		
	}
	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					
	}
	
	
	//$(".gallery-news a[rel^='prettyPhoto']").prettyPhoto();
	$(".gallery a[rel^='prettyPhoto']").prettyPhoto();
	
	//$(".tweet").corner("10px");
	$(".quote").corner("10px");
	
	/* image effects */
	
	/*$("#request-more-info").hover(function(){
		$(this).attr("src","images/request-more-info.jpg");
	});
	$("#request-more-info").mouseout(function(){
		$(this).attr("src","images/request-more-info-hover.jpg");
	});
	
	$("img#view-our-services").hover(function(){
		$(this).attr("src","images/view-our-services-hover.jpg");
	});
	$("img#view-our-services").mouseout(function(){
		$(this).attr("src","images/view-our-services.jpg");
	});*/
	
	$("#learn-go").click(function(){						  
		var service = $("#learn").val();
		if (service=="") alert("Please select a service");
		else window.location = "s.asp?s=" + service;
	});
	
	// site search
	$("#quick-search-button").click(function(){
		var url = "";
		var terms = "";
		if ($("#quick-search").val() != ""){
			var arr = $("#quick-search").val().split(" ");
			for (i=0; i<arr.length; i++){
				terms += arr[i] + "+";
			}
		url = "http://www.google.com/search?hl=en&q=" + terms + "site%3Awww.marketpointglobal.com&aq=f&oq=&aqi="
		window.location = url;
		}
	});
	
	$("#nav li a").bind('click', function(){
		$("#nav li").removeClass("currentPage");
		if($(this).parent().hasClass('subbrand')) $(this).parent().parent().addClass("currentPage");
		else $(this).parent().addClass("currentPage");
	});
	
	$("#cse-search-button").click(function(){
		$("#cse-search-box").submit();								   
	});
	

	
	$("#quick-search").keypress(function(e){
		var characterCode 
		
		if(window.event) // IE
		  { characterCode = e.keyCode; }
		else if(e.which) // Netscape/Firefox/Opera
		  { characterCode = e.which; }
				
		if(characterCode == 13){ 
		//trigger
		$("#quick-search-button").trigger("click");
		}
		
		});
	
	var url = document.location.href;
	var arr = url.split("/");
	var page = arr[arr.length -1];
	var arr2 = page.split(".asp");
	var str = arr2[0];
	
	if (str=="index"){ setCurrentPage("Home"); }
	else if (str=="services"){ setCurrentPage("Services"); }
	else if (str=="service"){ setCurrentPage("Services"); }
	else if (str=="news"){ setCurrentPage("News"); }
	else if (str=="clients"){ setCurrentPage("Our Clients"); }
	else if (str=="locations"){ setCurrentPage("Locations"); }
	else if (str=="contact"){ setCurrentPage("Contact"); }
	else if (str=="services-form"){ setCurrentPage("Services"); }
	else if (str=="aboutus"){ setCurrentPage("About Us"); }
	else if (str=="nurture"){ setCurrentPage("nurture"); }
	else if (str=="data"){ setCurrentPage("data"); }
	else if (str=="response"){ setCurrentPage("response"); }
	
}
function setCurrentPage(page){
	//set the nav item to have the hover class
	$("#nav li a").each(function(){
	 if ($(this).html()==page) $(this).parent().addClass("currentPage");
	 if ($(this).html().indexOf(page) > 0) $(this).parent().parent().addClass("currentPage");
	 });
}
function scrollUp(px){
if($.browser.opera){
$('html').animate({scrollTop: px}, 500);
} else $('html,body').animate({scrollTop: px}, 500);
}
// a function to parse the user agent string; useful for 
// detecting lots of browsers, not just the iPad.
function checkUserAgent(vs) {
    var pattern = new RegExp(vs, 'i');
    return !!pattern.test(navigator.userAgent);
}
