// JavaScript Document

$(document).ready(function() {

    /* MAIN MENU INITIALIZATON */

    $('#menu-bar').pixelMenu({
	moreText: ' +'
    });
	
	
	/* FEATURE LIST */
	
	$.featureList(
		$("#tabs li a"),
		$("#output li"), {
			start_item	:	0
		}
	);
	
    
	/* SLIDER-ROTATOR */
   
	$(".container").wtRotator({
		width:700,
		height:300,
		button_width:24,
		button_height:24,
		button_margin:5,
		auto_start:true,
		delay:5000,
		transition:"fade",
		transition_speed:800,
		cpanel_position:"inside",
		cpanel_align:"BR",
		timer_align:"top",
		display_thumbs:false,
		display_dbuttons:true,
		display_playbutton:true,
		display_numbers:false,
		display_timer:true,
		mouseover_pause:false,
		cpanel_mouseover:false,
		text_mouseover:false,
		text_effect:"fade",
		text_sync:true,
		tooltip_type:"image",
		shuffle:false,
		block_size:75,
		vert_size:55,
		horz_size:50,
		block_delay:25,
		vstripe_delay:75,
		hstripe_delay:180					
	}); 
		
    
	/* FANCYBOX Gallery */
	
	$(".lightbox").fancybox({
				'titleShow': true,
				'transitionIn'	: 'fade',
				'transitionOut'	: 'fade'
	});
	
	
	/* FANCYBOX Popup */
	
	$("a.inline").fancybox({
				'width'	: 400, 
				'height': 'auto' 
	});
	$("a.iframe").fancybox({
		'width'				: 180,
		'height'			: 300,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	
	/* Gallery THUMBS HOVER */	
	
	//resize the a tag
	var img_width_base = $('#gallery_content ul li img').width();
	var img_height_base = $('#gallery_content ul li img').height();
	
	var img_width = (img_width_base + 8);
	var img_height = (img_height_base + 8);
	
	$('#gallery_content ul li a').css({ width: img_width, height: img_height });
	
	//hover effect
	$('#gallery_content ul li').hover(function() {
		
		$(this).children('a').show();
		$('#gallery_content ul li').stop().animate({ opacity: .5 }, 300);
		$(this).stop().css('opacity', 1);
		
	}, function() {
		
		$(this).children('a').hide();
		
		$('#gallery_content ul li').stop().animate({ opacity: 1 }, 300);
		
	});


    /* FORM VALIDATION */
	
	$('form#contact_form').submit(function() {
		$('form#contact_form .error').remove();
		var hasError = false;
		$('.requiredField').each(function() {
			if(jQuery.trim($(this).val()) == '') {
            	var labelText = $(this).prev('label').text();
            	$(this).parent().append('<span class="error">'+labelText+'.</span>');
            	$(this).addClass('inputError');
            	hasError = true;
            } else if($(this).hasClass('email')) {
            	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            	if(!emailReg.test(jQuery.trim($(this).val()))) {
            		var labelText = $(this).prev('label').text();
            		$(this).parent().append('<span class="error">'+labelText+'.</span>');
            		$(this).addClass('inputError');
            		hasError = true;
            	}
            }
		});
		if(!hasError) {
			$('form#contact_form input.submit').fadeOut('normal', function() {
				$(this).parent().append('');
			});
			var formInput = $(this).serialize();
			$.post($(this).attr('action'),formInput, function(data){
				$('form#contact_form').slideUp("fast", function() {
					$(this).before('<p class="success">Thank you! Your message was successfully sent.<br>We will contact you.</p>');
				});
			});
		}

		return false;

	});
   
});
