$(document).ready(function(){

/*
 * 		Top Navigation (Dropdown Menu)
 */


	(function($) {
		$("#nav li.sub").hover(
			function() {
				$(this).find('ul:not(:animated)').fadeIn("fast");
				$('ul:first',this).css('visibility', 'visible');
			},
			function() {
				$(this).find('ul:not(:animated)').fadeOut("fast");
				$('ul:first',this).css('visibility', 'hidden');
			}
		)
	})(jQuery);

           
/*
 * 		Cycle functions (jquery.cycle.js)
 */

	// Add 'scrollVert' functionality for scroll boxe
	(function($) {

		$.fn.cycle.transitions.scrollVert = function($cont, $slides, opts) {
		    $cont.css('overflow','hidden');
		    opts.before.push(function(curr, next, opts, fwd) {
		        $(this).show();
		        var currH = curr.offsetHeight, nextH = next.offsetHeight;
		        opts.cssBefore = fwd ? { top: -nextH } : { top: nextH };
		        opts.animIn.top = 0;
		        opts.animOut.top = fwd ? currH : -currH;
		        $slides.not(curr).css(opts.cssBefore);
		    });
		    opts.cssFirst = { top: 0 };
		    opts.cssAfter = { display: 'none' }
		};

	})(jQuery);


/*
 * 		Latest News Scroller
 */

	$('#scrollNews ul').cycle({ 
	    fx: 'scrollVert',
		speed: 650,
		rev: true,
		timeout: 10000,
		next:   '#scrollNews ol li.next', 
	    prev:   '#scrollNews ol li.previous'
	});


/*
 * 		Spotlight Scroller
 */

	$('#scrollSpotlight ul').cycle({ 
	    fx: 'scrollVert',
		speed: 850,
		rev: true,
		timeout: 10000,
		next:   '#scrollSpotlight ol li.next', 
	    prev:   '#scrollSpotlight ol li.previous'
	});

	
	
	/******* Contact Form Validation 
	**********************************/
	
	$('#contactform').submit(function() {
	
		// Disable the submit button
		$('#contactform input[type=submit]')
		.attr('value', 'Sending message...')
		.attr('disabled', 'disabled');

		$.post("mail.php", {
			call: 'contact',
			name:$('#name').val(),
			company:$('#company').val(),
			email:$('#email').val(),
			country:$('#country').val(),
			message:$('#message').val(),
			code:$('#code').val()
		},
	  	function(errors) {
			// No errors  
			if (errors == 1) {
				$('#contactform')
					.hide()
					.html('<div class="whitepaper"><h3>Thank you</h3><p>Your message has been received, one of our specialist will contact you at the earliest.</p></div>')
					.show();
			}
			// Errors
			else {
				// Re-enable the submit button
				$('#contactform input[type=submit]').removeAttr("disabled").focus().val("Send your Question");		
				
				// Technical server problem, the email could not be sent
	    		alert("Data Loaded: " + errors);
    		}
		});

		// Prevent non-AJAX form submission
		return false;
	});
	
	/******* Request Information Form Validation 
	**********************************/
	
	$('#requestform').submit(function() {
	
		// Disable the submit button
		$('#requestform input[type=submit]')
		.attr('value', 'Sending message...')
		.attr('disabled', 'disabled');

		$.post("mail.php", {
			call: 'requestinfo',
			name:$('#name').val(),
			company:$('#company').val(),
			email:$('#email').val(),
			country:$('#country').val(),
			phone:$('#phone').val(),
			solution:$('#solution').val(),
			budget:$('#budget').val(),
			currency:$('#currency').val(),
			project:$('#project').val(),
			code:$('#code').val()
		},
	  	function(errors) {
			// No errors  
			if (errors == 1) {
				$('#requestform')
					.hide()
					.html('<div class="whitepaper"><h3>Thank you</h3><p>Your details have been received, one of our specialist will contact you at the earliest.</p></div><br /><br /><br /><br />')
					.show();
			}
			// Errors
			else {
				// Re-enable the submit button
				$('#requestform input[type=submit]').removeAttr("disabled").focus().val("Send your Question");		
				
				// Technical server problem, the email could not be sent
	    		alert("Data Loaded: " + errors);
    		}
		});

		// Prevent non-AJAX form submission
		return false;
	});

});

