var j = jQuery.noConflict();

j(document).ready(function() {

 /* Homepage - Full Screen Display */
 j("a.fullsize").click(function(){
 j("div.header").slideToggle("slow","easeInOutBack");
 j(this).toggleClass("active");
 return false;
 });

 /* Global - Dropdown Navigation */
 j('.nav li ul').hide();
 j('.nav li').hover(function(){
 j(this).find('ul').show();
 },
 function(){
 j(this).find('ul').hide("fast","easeOutSine")
 ;})

 LoadFadeImage();
 LoadImageLoading();
 
/*
 * 		Top Navigation (Dropdown Menu)
 */


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

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

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

		j.fn.cycle.transitions.scrollVert = function(jcont, jslides, opts) {
		    jcont.css('overflow','hidden');
		    opts.before.push(function(curr, next, opts, fwd) {
		        j(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;
		        jslides.not(curr).css(opts.cssBefore);
		    });
		    opts.cssFirst = { top: 0 };
		    opts.cssAfter = { display: 'none' }
		};

	})(jQuery);


/*
 * 		Latest News Scroller
 */

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


/*
 * 		Spotlight Scroller
 */

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


/*
 * 		Contact Form Validation
 */


	j('#contactform').submit(function() {
	
		// Disable the submit button
		j('#contactform input[type=submit]')
			.attr('value', 'Sending message…')
			.attr('disabled', 'disabled');
	
		// AJAX POST request
		j.post(
			j(this).attr('action'),
			{
				name:j('#name').val(),
				email:j('#email').val(),
				message:j('#message').val()
			},
			function(errors) {
				// No errors
				if (errors == null) {
					j('#contactform')
						.hide()
						.html('<h3>Thank you</h3><p>Your message has been sent.</p>')
						.show();
				}
	
				// Errors
				else {
					// Re-enable the submit button
					j('#contactform input[type=submit]')
						.removeAttr('disabled')
						.attr('value', 'Send your Question');
	
					// Technical server problem, the email could not be sent
					if (errors.server != null) {
						alert(errors.server);
						return false;
					}
	
					// Empty the errorbox and reset the error alerts
					j('#contactform .errorbox').html('<ul></ul>').show();
					j('#contactform li').removeClass('alert');
	
					// Loop over the errors, mark the corresponding input fields,
					// and add the error messages to the errorbox.
					for (field in errors) {
						if (errors[field] != null) {
							j('#' + field).parent('li').addClass('alert');
							j('#contactform .errorbox ul').append('<li>' + errors[field] + '</li>');
						}
					}
				}
			},
			'json'
		);
	
		// Prevent non-AJAX form submission
		return true;
	}); 

})

/* Image Loading Effect */
var i = 0;
var int=0;

function ImageLoading() {
 var images = jQuery('.load').length;
 if (i >= images) {
 clearInterval(int);
 delete int;
 }
 jQuery('.load:hidden').eq(0).fadeIn(200);
 i++;
}

function LoadImageLoading() {
 j('.load').hide()
 setInterval("ImageLoading(i)",500);
}

/* Image Fade Effect */
function LoadFadeImage() {
 j(".fade").fadeTo(125, 0.9);

 j(".fade").hover(function(){
 j(this).fadeTo(75, 1.0);
 },

 function(){
 j(this).fadeTo(125, 0.9);
 });
}

