$(function() {

/** CSS */
	var w = $(window).width();
	var h = $(window).height();
	var s = (w/2)-480;
	$('.sub').css({
		'width' :w+'px',
		'padding-left' :s+'px',
		'padding-right' :s+'px'
	});

/** ACCORDIONS */
	$('#service_slider').accordion({ clearStyle:true });
	$('#about_slider').accordion({ clearStyle:true });

/** OVERLAYS */
	$('a[rel]').overlay({
		expose:'#070a18',
		effect:'apple'
		});

/** ROUND THOSE CORNERS */
if ($.browser.msie) {
	$('h3').corner('10px');
	$('.portfolio_overlay .portfolio_visit a').corner('8px');
}

/** FRONT PAGE SCROLLER */
  $('div#featured').scrollable({
    size:1,
    clickable:false
  }).circular().autoscroll(4000);

/** TOOLTIPS */
  $('#about_slider img[title]').tooltip({
      tip:'#bigtip',
      position:'bottom center',
      effect:'slide',
      direction:'down'
	});

  $('#service_slider img[title]').tooltip({
    tip:'#tip',
    position:'bottom center',
    effect:'slide',
    direction:'down'
	}).dynamic({
        top:{
            direction:'up',
            bounce:true
        }
	});

/** ABOUT PAGE IMAGE TOGGLE */
	$('#about_image').toggle(
		function () {
			$('#img2').show(),
			$('#img1').hide();
		},
		function () {
			$('#img1').show(),
			$('#img2').hide();
		}
	)

/** PORTFOLIO PAGE FILTER */
	$('ul#filter a').click(function() {
		$(this).css('outline','none');
		$('ul#filter .current').removeClass('current');
		$(this).parent().addClass('current');

		var filterVal = $(this).text().toLowerCase().replace(' ','-').replace(' ','-');

		if(filterVal == 'all') {
			$('ul#portfolio_page li.hidden').fadeIn('slow').removeClass('hidden');
		} else {
			$('ul#portfolio_page li').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}
		return false;
	});

/** PORTFOLIO PAGE IMAGE CAPTIONS */
	$('ul#portfolio_page li').hover(function(){
			$('.caption', this).stop().animate({top:'-32px'},{queue:false,duration:200});
		}, function() {
			$('.caption', this).stop().animate({top:'0px'},{queue:false,duration:200});
	});

/** CONTACT FORM AJAX SUBMIT */
	$('#contact-form').validate({
         submitHandler: function(form) {
           $(form).ajaxSubmit({
                success: function() {	
		      		$('#contact-form').resetForm();	
                    $('#msg').html( 'Thank you. Your message was sent.<br />I will get back to you soon.');
				}
           });
         }
    });
	
/** BACKGROUND SCROLL */
	var backgroundheight = 1000;
	var offset = 0;
	function scrollbackground() {
		offset = (offset < 1) ? offset + (backgroundheight - 1) :offset - 1;
		$('#container').css('background-position', '50% ' + offset + 'px');
		setTimeout(function() {
			scrollbackground();
		}, 100
		);
	}
	scrollbackground();

/** SITE SCROLLING CONTENT */
	$.localScroll.defaults.axis = 'x';

	$.localScroll.hash({
		target:'#content',
		queue:true,
		axis:'x',
		duration:1500
	});

	$.localScroll({
		target:'#content',
		queue:true,
		duration:1000,
		hash:true,
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});

});
