$(function() {
	
	$('.image_box').cycle({ 
    	fx:     'fade', 
    	prev:   '#prev_img', 
    	next:   '#next_img', 
    	after:   onAfter, 
    	timeout: 0 
	});
	

	$('li.dropdown_menu').hover(function() {
		
		$('ul.inner_menu',$(this)).show();
	},
	function() {
		
		$('ul.inner_menu',$(this)).hide();
		
	});
	
	$("a[rel=example_group]").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$('#fancybox-right-ico').live('click', function(){
		$.fancybox.next();							   
	});
	
	$('.show_more').click(function(){
		$('#news_list li').each(function(){
			$(this).show();
		});		
		$(this).hide();
	});
	
	$('#contact_form').validate({
		errorLabelContainer: '#error_msg',
		rules: {
			name: {
				required: true
			},
			email: {
				email: true,
				required: true
			},
			phone: {
				required: true
			},
			enquiry_type: {
				required: true	
			}
		},
		messages: {
			name: '',
			phone: '',
			email: {
				required: '',
				email: 'Please enter a valid email address'
			},
			enquiry_type: 'Please select enquiry type'
		},
		highlight: function(element, errorClass, validClass) {
				$(element).addClass(errorClass).removeClass(validClass);
		},
		unhighlight: function(element, errorClass, validClass) {
				$(element).removeClass(errorClass).addClass(validClass);
		},
		submitHandler: function() {
			$('#error_msg').html('Please wait...');
			$('#error_msg').css("color","white");
			$('#error_msg').show();
			$.ajax({
				type: "POST",
				url: base_url + "ajax/request_call_back",
				data: $('#contact_form').serializeArray(),
				success: function(msg){
					if (msg == 'success'){
						$('#error_msg').html('Your email has been sent successfully ... we will be in touch very soon. Thank you');
					}else{

						$('#error_msg').html(msg);
						$('#error_msg').css("color","#FF0000");
						$('#error_msg').show();
					}
				}
			});
		}
	});
});

function onAfter(curr, next, opts) {
    var index = opts.currSlide;
    $('#prev_img')[index == 0 ? 'hide' : 'show']();
    $('#next_img')[index == opts.slideCount - 1 ? 'hide' : 'show']();
}

