$(document).ready(function() {
	
	$('input[type=checkbox]').css('border', 'none');
	
	// system messages
   $("#sysMsg").fadeIn("slow");
	setTimeout("$('#sysMsg').fadeOut('slow')",3000)		
	// IE problem fix
	if (navigator.appName == "Microsoft Internet Explorer") {	
	//	setInterval("fixFooter()", 500);
	}
	
	$('.eventOnList').mouseover(function() {
		
	});
	$('.eventOnList').mouseout(function() {
		
	});	
	
	$('#submit-contact-form').bind('click', function() {
		var email = $('#contact-form-email').val();
		var issue = $('#contact-form-issue').val();
		var content = $('#contact-form-content').val();
		var category = $('#contact-form-category').val();
		var module = $('#contact-form-module').val();
		 if(isValidEmail(email)) {
			$('#contact-form form').fadeOut(); 	
			$('#contact-form').append('<img id="loader" src="/images/ajax-loader.gif" alt="sending..." />');
			if(category){
				$.ajax({
				   type: "POST",
				   url: "/index/contact-me",
				   data: "email=" + email + "&content=" + content + "&issue=" + issue + "&category=" + category,
				   success: function(msg){
				     $('#contact-form #loader').fadeOut(function() {
				     	$('#contact-form-message').fadeIn();
				     });
				   }
				 });
			}else if(module){
				$.ajax({
				   type: "POST",
				   url: "/index/contact-me-module",
				   data: "email=" + email + "&content=" + content + "&issue=" + issue + "&moduleId=" + module,
				   success: function(msg){
				     $('#contact-form #loader').fadeOut(function() {
				     	$('#contact-form-message').fadeIn();
				     });
				   }
				 });
			}
		 }
	});
	$('#background').cycle({
			fx: 'fade',
			pause:  3
	});	
});

function isValidEmail(strEmail){
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(strEmail)) {
		return false;
	}
	return true;
}

function addUser($invalidEmail, $exists, $thanks){
	$email = document.getElementById('newsletterMail').value;
	if(isValidEmail($email)){
		$.ajax({
				type: "POST",
				url: "/default/newsletter/add-user",
				data: "email=" + $email ,
				success: function(msg){
					if(msg == 'exists')
				   		$("#newsletterLabel").text($exists);
				   	else if(msg == 'ok')
				   		$("#newsletterLabel").text($thanks);
				}
		});
	}else{
		$("#newsletterLabel").text($invalidEmail);
	}
}

function fixFooter() {
		var boxesH = $('#boxes_right').height();
		var pageH = document.documentElement.clientHeight;
	 if (boxesH > pageH) {
	 	var heigher = boxesH - pageH/2;
	 	$('#bottom').css('margin-top', heigher + "px");
	 } 
}
