(function($) {

	function setup_home()
	{
		$("#home_slider").each(function(){
			
			$(this).wtRotator({
				width:830,
				height:465,
				auto_start:true,
				delay:5000,
				play_once:false,
				transition:"blinds.top",
				transition_speed:1000,
				auto_center:true,
				easing:"",
				display_thumbs:false,
				display_dbuttons:false,
				display_playbutton:false,
				display_numbers:false,
				display_timer:false,
				mouseover_pause:false,
				cpanel_mouseover:false,
				text_mouseover:false,
				horz_size:20,
				hstripe_delay:0			
			});
			
		});
		
	}
	
	
	function setup_background()
	{
		/* 
		
		Markup should look like this:
		
		<div class="background">
			<img src="images/layout/background.jpg" alt="background" />
		</div>
		
		*/
		
		var div = $('.background');
		var img = div.find('img');
		
		$(window).resize(function(){
		
			img.css({'width' : $(window).width(), 'height' : 'auto'});
			
			if(img.height() < $(window).height())
			{
				img.css({'width' : 'auto', 'height' : $(window).height()});
			}
		
		}).trigger('resize');
		
	}
	
	
	$(document).ready(function(){
		
		// twitter
		var username='designbydu'; // set user name
		var format='json'; // set format, you really don't have an option on this one
		var url='http://api.twitter.com/1/statuses/user_timeline/'+username+'.'+format+'?callback=?'; // make the url

		$.getJSON(url,function(tweet){ // get the tweets
			$("#utility li.twitter span p").html(tweet[0].text); // get the first tweet in the response and place it inside the div
		});
		
		$("#utility li").each(function(){
			
			$(this).hover(function(){
				$(this).addClass('active');
				$(this).find(".label").fadeIn();
			}, function(){
				$(this).removeClass('active');
				$(this).find(".label").fadeOut();
			})
			
			
			/*$(this).click(function(){
				return false;
			});*/
			
		});
		
		
		$("#utility_top").click(function(){
			window.location = "#";
		});
		
		
		// fancybox
		$("a.fancybox").fancybox({
			'overlayColor'	:	'#000',
		});
		
		
		// fancybox
		$("a.fancybox_video").click(function(){
             $.fancybox({
              'overlayColor'		: '#000',
              'autoScale'   		: false,
              'width'               : 680,
              'height'              : 495,
              'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
              'type'                : 'swf',    // <--add a comma here
              'swf'                 : {'allowfullscreen':'true'} // <-- flashvars here
              });
             return false;

        }); 		
		
		// contact form 
		$('form').each(function(){
			$(this).validate({
				highlight: function(element, errorClass, validClass) {
				    $(element).closest('.field').addClass('error');
				},
				unhighlight: function(element, errorClass, validClass) {
				    $(element).closest('.field').removeClass('error');
				}
			});
		})
		
		// home 
		setup_home();
		setup_background();
	});
	
	$(window).load(function(){
		setup_background();
	});

})(jQuery);
