var J=jQuery.noConflict();
var puth = "";

J(document).ready(function(){
	initContactForm();
	J('div.footer li:last-child').addClass('last');
	J('.right-links li:first-child').addClass('first'); 
})

function initContactForm(){
	J('form#email-form').submit(function(){
		var form = J(this);
		var formData = J(this).serialize();
		var error = '';
		J.ajax({
			type: 'POST', url: form.attr('action'), data: formData, 
			success: function ( responseData ){
				if((error = Process(responseData)) != ''){
					J('form .error').hide();
					J('form .'+error).fadeIn();
				} else{
					document.getElementById('email-form').reset();
					J('form .error').hide();
					form.hide('normal');
					J('.thank-you').hide();
					J('.thank-you').show('normal');
					window.location = puth;
				}
			}
		});
		
		return false;
	});
}

function Process(str){
	list = str.split(':');
	if(list[0].toLowerCase() != 'done'){
		return list[0];
	} else {
		puth = list[1];
		return '';
	}
}

var t = null;
J(document).ready(function($){
	
	//Add ID For .navigation LI
	$(".navigation LI").each(function(i,el){$(this).attr("id","image-slider-"+(i+1));});
	// init first image
	slide("image-slider-1"); 
	// set timeout
	t = setTimeout('slide()',5000000000);
	J(".navigation a").click(function(){
		if ( $(this).parent().hasClass("selected") ) return true;
		clearTimeout(t);
		slide($(this).parent().attr("id")); 
		return false;
	});
	J('form.loginform p:eq(8),form.loginform p:eq(9),form.loginform p:eq(10),form.loginform p:eq(11),form.loginform p:eq(12),form.loginform p:eq(13)').addClass('clear');
	J(":radio").uniform();
	J(":checkbox").uniform(); 
	J("div.registration h1").after("<p id='registerpara'>The VM6 Software resource center is designed to provide you with all the information you need to know about virtualizing your ROBO, SMB and Web Hosting operations.</p>");
	J("div.registration h1").prepend("Resources ");
	J("div.registration h1").replaceText( /Register/gi, "Registration" );
	J("div.registration p#registerpara + div.right-links").addClass('hideme');
	J("div.registration p:eq(1), div.registration input:eq(0)").addClass('first');
	J("div.registration p:eq(1) label:eq(1)").addClass('second');
});


function slide(nextId){
	if ( !J(".navigation") || J(".navigation").length == 0) return true;
	var curId = J(".navigation .selected").attr("id");
	if (!nextId) {
		var nextId = J(".navigation .selected").next('li').attr("id");
		if (!nextId || $(nextId).length == 0) nextId = J(".navigation li:first").attr("id");
	}	
	
	J(".navigation .selected").removeClass("selected");
	J("#"+nextId).addClass("selected");
	
	//Set Image to background
	J(".sub-page").css("background","");
	J("."+nextId+" img").removeClass("hidden");
	
	J(".empty").css("display","none");
	if ( !J("div."+nextId+" img").hasClass("structure") ) {
		J("div."+nextId+" img").addClass("hidden");
		J(".sub-page").css("background","url("+J("div."+nextId+" img").attr('src')+") no-repeat left top");
		J(".empty").css("display","block");
		J(".empty").css("height","311px");
	}
	if ( J("."+nextId+" img").length == 0 ) {
		J(".empty").css("display","block");
		J(".empty").css("opacity",0);
		J(".empty").css("background","#000000");
		J(".empty").css("height","311px");
	}
	
	
	J("."+curId).addClass("hidden");
	J("."+nextId).removeClass("hidden");
	t = setTimeout('slide()',5000);
	return;
}