$(document).ready(function(){
	
	popup();
	
	imagePreview();
	
	$('#submit').attr("disabled", true);
	
	$('.nameRollover').simpletooltip();
	
	$('.answer').hide();
	$('.question p').hover(function () {
		$(this).css({'color' : '#666666'});
	}, 
	function () {
		$(this).css({'color' : '#000000'});
	});
		  	       	            	 
	$('.question').bind("click", function(){
		if($(this).next(".answer").is(':visible')) {
			$(this).next(".answer").slideUp('fast');
		} else {
			$('.answer').slideUp('fast');
			//setTimeout(function() { $(this).siblings(".answer").slideDown('fast'); }, 1000);
			$(this).siblings(".answer").delay(250).slideDown('fast');
		}
	});
		 	 	       	            	 	 	  	  
	
	$('#homeSlideshow').innerfade({
//		animationtype: 'slide',
		speed: 1000,
		timeout: 6000,
		type: 'random',
		containerheight: '420px'
	});
	
	$("div#footer-navigation div").each(function() {
		 $(this).css("height", $(this).height());
		 $("p", this).css({
		 	display: 'none',
		 	visibility: 'visible'
 		});
	});

 	$("div#footer-navigation div").hover(function() {
		 $(this).children("p").slideDown(200);
		 }, function() {
		 $(this).children("p").slideUp(200);
 	});
 	
 	$("div#footer-navigation div").click(function() {
 		location.href = $("a", this).attr("href");
 	}); 
});

this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


function popupWindow(url, name, attributes){
	var newWindow = window.open(url, name, attributes);
	newWindow.focus();
} 


function popup() {
	$('a.popupLink').bind('click', function(e) { popupWindow($(this).attr('href'), $(this).attr('title').replace(/[^A-z]/ig, ''),'width=500, height=500, scrollbars'); e.preventDefault(); });
};

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 email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email address")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){

	var emailID=document.subscribeForm.cm-atte-atte;
	//var emailID = $('#atte-atte').attr("value");
	//alert(emailID);
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

