var basepath = 'http://' + window.location.host + '/';
var urlsplits = (window.location.pathname).split('/');
if(urlsplits[1] == 'deco') basepath = basepath + (window.location.pathname).split('/')[1] + '/';
timestamp = Number(new Date());

// AND AWAY WE GO...
$(document).ready(function() {
	 	
  	// Tabs
  	$("#tabs").idTabs( function(id,list,set) { 
    	$("a",set).removeClass("selected").filter("[href='"+id+"']",set).addClass("selected"); 
    	for(i in list) $(list[i]).hide(); 
    	$(id).fadeIn(); 
    	return false; 
  	});
  	
  	// sIFR
    $('#main h2').not('.ir').flash(
        { 
            src: basepath + 'assets/swf/neu_demi.swf', 
            flashvars: { 
                css: [
                    '* { color: #222222; letter-spacing: -1px; }'
                ].join(' ')
            }
        },
        { version: 8 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = $alt.height();
            htmlOptions.width = $alt.width();
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );
    
	// Pricing
	$('#priceselgo').click( function() {		
		var loc = $('#pricesel').val();
		if(loc!='--')
		{
			$('#pricing-select').hide();
			$('div#pricing-' + loc).show();
		}		
	}); 
	
	// Image cycling.
	$('#v-imgs').cycle({ 
	    fx:      'fade', 
	    speed:    500, 
	    timeout:  3000
	})	
	
	// Contact validation.
	$("#contact-form").validate({
		rules: {
			name: {
				required: true
			},
			email: {
				required: true,
				email: true
			}
		},
		errorElement: "span",
		errorClass: "form-error",
		errorPlacement: function(error, element) {
			error.appendTo(element.parent("p"));
		},
		submitHandler: function(form) {
			$(form).ajaxSubmit({
				beforeSubmit: function(fd, form) {
					$(form).fadeTo(300, 0.5).find('button').attr('disabled', 'disabled');					
				},
				success: function(data, statusText, xhr, $form) {
					$form.fadeTo(300, 1).find('button').attr('disabled', '');
					$('#form-msg-area').html(data.msg);
				},
				dataType: 'json',
				resetForm: true			
			});
		}
	})
});