/////////////////////////////.///////////////////
// JQUERY AJAXSUBMIT SETTINGS FOR CONTACT FORM //
/////////////////////////////.///////////////////
var optionsCallBack = { 
//		beforeSubmit:	showRequest,
	target:			'#thankyou_container',				// target element(s) to be updated with server response 
	success:		responseCallBack,	// post-submit callback 
	dataType:		'json',					// 'xml', 'script', or 'json' (expected server response type) 
	url:			'/_ajax/callback.cfm',	// override for form's 'action' attribute 
	clearForm:	true,						// clear all form fields after successful submit 
	resetForm:	true			// reset the form after successful submit 
	
	// other available options: 
	//type:			type			// 'get' or 'post', override for form's 'method' attribute 
	//resetForm:	true			// reset the form after successful submit 

	// $.ajax options can be used here too, for example: 
	//timeout:   3000 
};

/**************************************************************************************************************/

$(document).ready(function(){
	$(".callback_link").colorbox({width:"480px", height:"400px", inline:true, href:"#callback_container"});
	
	$("#inside_thankyou").hide();
	
	$("#callback_form a").click(function(){
		$('#callback_form').submit();
	});
	
	$("#inside_thankyou a").click(function(){
		location.reload();
	});
	
	// LOAD OVERVIEW COPY BY DEFAULT
	$("#product_copy").html($("div#overview_content").html());
	$('a#overview').addClass('on');
	
	// LOAD CONTENT AND SET NAV TAB STYLES WHEN CLICKING ON TAB BUTTONS
	$('#productNav div.tabs a').click(function() {
		var id = $(this).attr('id');
		var arr_tabs = new Array();
		
		// UPDATE NAV STYLES : START
		arr_tabs[0] = 'overview';
		arr_tabs[1] = 'main_features';
		arr_tabs[2] = 'key_benefits';
		for (i=0;i < arr_tabs.length;i++) {
			if (id == arr_tabs[i]) {
				$('a#' + arr_tabs[i]).addClass('on');
				$("#product_copy").html($('#' + id + '_content').html()); // POPULATE CONTENT
				activate_next_tab();
			} else {
				$('a#' + arr_tabs[i]).removeClass('on');
			}
		}
		// UPDATE NAV STYLES : ENDS
	});
	
	// ACTIVATE THE NEXT TAB BUTTON
	activate_next_tab();
	
	/////////////////////////////.//////////////////
	// SET UP JQUERY VALIDATION FOR CALL ME BACK FORM //
	/////////////////////////////.//////////////////
	
	$("#callback_form").validate({
		submitHandler : function(form) {
			$("#callback_form").ajaxSubmit(optionsCallBack);
		},
		rules : {
			name	: "required",
			number	: {
				required	: true
			}
		},
		messages : {
			name	: "Sorry, what's your name",
			number	: {
				required	: "Please type in your number"
			}
		}
	});
});

function responseCallBack() {
	$("#inside_callback").hide();
	$("#inside_thankyou").show();
}

function activate_next_tab() {
	$('a.next_tab').click(function() {
		var tab_on = false;
		var id = '';
		$('#productNav p a').each(function(idx, item) {
			if (tab_on) id = $(item).attr('id');
			if ($(item).attr('class') == 'on') {
				tab_on = true;
			} else {
				tab_on = false;
			}
		});
		$('#' + id).trigger('click');
	});
}
