//begin 
//$(document).ready(function(){
$(window).load(function() {

	//Enter website
	$('#loading').fadeOut(200).slideUp(1);
	$('#logo').bounce(0,-20,0,300,100,300,true,80,'.logoani');	
	$('#menu').menuEnter();	
	$('#footer').footerEnter();

	/*Anchor system*/
	if (window.location.hash == '#/About'){
		$('.mabout').menu(0);
		$('#about').page();
	} else if (window.location.hash == '#/Service') {
		$('.mservice').menu(0);
		$('#service').page();
	} else if (window.location.hash == '#/Portfolio') {
		$('.mportfolio').menu(0);
		$('#portfolio').page();
	} else if (window.location.hash == '#/Blog') {
		$('.mblog').menu(0);
		$('#blog').page();
	} else if (window.location.hash == '#/Contact') {
		$('.mcontact').menu(0);
		$('#contact').page();
	} else if (window.location.hash == '#/Contact/Mail') {
		$('.mcontact').menu(0);
		$('#contact').page();
		$('#mail').mailForm();
	} else {
		window.location.hash = '#/Home'
		$('.mhome').menu(0);
		$('#home').page();
		$('#menu .left img').fadeOut(0);
	}
	

	// Logo hover
	$('#logo img').hover(function() {
		$('#logo .logoani').wobble(10);
	}, function() {
		$('#logo .logoani').wobble(20, true);
	});
	
	$('#logo img').click(function(){
		$('#menu .mhome').menu();
	});
	
	
	// Menu
	$('#menu ul li').click(function(){
		$(this).menu();
	});
	$('#menu .left img, #menu .right img').click(function(){
		$(this).pnMove();
	});
	
	
	// About
	$('#about #me').hover(function() {
		$('#about #me').threeframes();
	}, function() {
		$('#about #me').stop();
	});
	
	
	// Portfolio
	$('#portfolio .next').hover(function() {
		$(this).animate({opacity: '0.7'}, 200);
	}, function() {
		$(this).animate({opacity: '1'}, 200);
	});
	
	$('#portfolio .previous').hover(function() {
		$(this).animate({opacity: '0.7'}, 200);
	}, function() {
		$(this).animate({opacity: '0.5'}, 200);
	});
	
	$('#portfolio .next, #portfolio .previous').click(function(){
		$(this).portfolioPN();
	});
	
	$('#portfolio .sel').css('top', '50%');

		
	// Contact page
	$('#contact .types div').hover(function() {
		$(this).find('.click').stop().delay(140).scale(0.4).animate({scale: '1', opacity: '1'}, 100);
	}, function() {
		$(this).find('.click').stop().delay(100).animate({scale: '0.4', opacity: '0'}, 100);
	});
	
	$('#contact .types .digital').click(function(){
		$('#mail').mailForm();
	});
	
	
	// Contact
	$('#form #send img').hover(function(){
		$('#form #send img').stop().animate({
			opacity: '1'
		}, 400);
	}, function(){
		$('#form #send img').stop().animate({
			opacity: '0'
		}, 400);
	});
	
	$('#form .letter .close').click(function(){
		$('#mail').mailForm();
	});
	
	
	$('#form #send img').click(function(){
		var name = $('#form .letter .name').val();
		var email = $('#form .letter .email').val();
		var website = $('#form .letter .website').val();
		var message = $('#form .letter .message').val();
		var checkpoint = $('#form .letter .code').val();
		if(name == 'Name'){
			$('#form input, #form textarea, #form input, #form input').removeClass('error');
			$('#form .name').addClass('error');
		} else if(name == ''){
			$('#form input, #form textarea, #form input, #form input').removeClass('error');
			$('#form .name').addClass('error');
		} else if(email == 'Email'){
			$('#form input, #form textarea, #form input, #form input').removeClass('error');
			$('#form .email').addClass('error');
		} else if(email == ''){
			$('#form input, #form textarea, #form input, #form input').removeClass('error');
			$('#form .email').addClass('error');
		} else if(message == ''){
			$('#form input, #form textarea, #form input, #form input').removeClass('error');
			$('#form textarea').addClass('error');
		} else {
			$('#form input, #form textarea, #form input, #form input').removeClass('error');
		
			$.ajax({
  				url: 'files/mail.php?name=' + name + '&email=' + email + '&website=' + website + '&message=' + message + '&checkpoint=' + checkpoint,
  				context: document.body,
  				success: function(){
  					$('#mail').mailForm();
					$('.delivered').animate({
						bottom: '23px'
					}, 400).delay(1200).animate({
						bottom: '-32px'
					}, 300);
					$('#form .name').val('Name');
					$('#form .email').val('Email');
					$('#form .website').val('Website');
					$('#form .message').val('Message');
  				}
			});
		}
	});
	
	
	// Contact Sidehover
	$('#form .side1 textarea').focus(function(){
		$(this).mailSide();
	});
	
	$('#form .side1 textarea').blur(function(){
		$(this).mailSide();
	});
	
	
	// Contact Remove text
	$('#form input').focus(function(){
		if ($(this).val() == 'Name'){
			$(this).val('');
		} else if ($(this).val() == 'Email'){
			$(this).val('');
		} else if($(this).val() == 'Website'){
			$(this).val('http://');
		}
	});
	
	$('#form input, #form textarea').blur(function(){
		if($(this).val() == ''){
			$(this).addClass('error');
		} else if($(this).val() == 'Name'){
			$(this).addClass('error');
		} else if($(this).val() == 'Email'){
			$(this).addClass('error');
		} else {
			$(this).removeClass('error');
		}
	});
	
	
	// Footer
	$('.clickmail').click(function(){
		$('#mail').mailForm();
	});
	
	$('#footer').hover(function(){
		$(this).stop().animate({
			opacity: '1'
		}, 400);
	}, function(){
		$(this).stop().animate({
			opacity: '0.6'
		}, 400);
	});
	
	$('#footer .right2').hover(function(){
		$(this).stop().animate({
			opacity: '1'
		}, 400);
	}, function(){
		$(this).stop().animate({
			opacity: '0.6'
		}, 400);
	});
	
	// Footer Keydown
	$('#footer .keydown img').click(function(){
		className = $(this).attr('class');
		
		if (className == 'imgright'){
			$('body').keyRight();
		} else if (className == 'imgleft'){
			$('body').keyLeft();
		} else if (className == 'imgup'){
			$('body').keyUp();
		} else if (className == 'imgdown'){
			$('body').keyDown();
		}
	});
	
	$('#footer .keydown img').hover(function(){
		$(this).stop().animate({opacity: '0.7'}, 400);
	}, function(){
		$(this).stop().animate({opacity: '1'}, 400);
	});
	
	// Tooltip
	// VSF FILE Footer Right
	$('#tooltip').fadeOut(0);
	
	$('.vsf').hover(function(){
		$(this).tooltip('DOWNLOAD *.VSF FILE');
	}, function(){
		$(this).tooltip('away');
	});
	
	$('#contact .digital .hover').hover(function(){
		$(this).tooltip('CLICK!');
	}, function(){
		$(this).tooltip('away');
	});

	
	/* Device extras */
	// Internet Explorer 6 7 8 9
	if (jQuery.browser.msie) {
    	//$('html').addClass('internetexplorer');
    	$('body').html('<a href="http://google.com/chromeframe" target="blank"><img class="iechromeframe" src="images/ie.png" alt="" /></a>');
	}
	
	
	// Firefox
	if (jQuery.browser.mozilla) {
    	$('html').addClass('firefox');
	}
	
	// iPad
	jQuery.extend(jQuery.browser,{SafariMobile : navigator.userAgent.toLowerCase().match(/iPad/i) });
	$(function(){
  		if($.browser.SafariMobile){
			$('html').addClass('ipad');
			window.location = "#/iPad/Home"
			
			/* SWIPE */
			// http://labs.skinkers.com/touchSwipe/
			var swipeOptions = { 
				swipe:swipe,
				threshold:150
			}		
			$(function(){			
				$('body').swipe(swipeOptions);
			});
  		}
	})
	// iPhone
	jQuery.extend(jQuery.browser,{SafariMobile : navigator.userAgent.toLowerCase().match(/iPhone/i) });
	$(function(){
  		if($.browser.SafariMobile){
			if(window.devicePixelRatio >= 2){
				$('html').addClass('iphone4');
				window.location = "#/iPhone4/Home"
				$('body').html('<img class="nopeiphone" src="images/iphone4.png" alt="" />');
			}else {
				$('html').addClass('iphone');
				window.location = "#/iPhone/Home"
				$('body').html('<img class="nopeiphone" src="images/iphone.png" alt="" />');
			}			
  		}
	})
	
//end	
});
