/* Functions by DSGN.US */

	/* Logo Animation */
	$.fn.wobble = function (speed,reverse) {
		if(reverse == true){
			$(this).stop().animate({
				backgroundPosition: '0px 0',
				left: '8px'
			}, 1).animate({
				backgroundPosition: '-198px 0',
				left: '9px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-198px 0',
				left: '9px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-396px 0',
				left: '10px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-595px 0',
				left: '11px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-792px 0',
				left: '11px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-595px 0',
				left: '11px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-396px 0',
				left: '10px'
			}, 1).delay(speed);
		} else {
			$(this).stop().animate({
				backgroundPosition: '-198px 0',
				left: '9px'
			}, 1).delay(speed).animate({
				backgroundPosition: '0px 0',
				left: '8px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-198px 0',
				left: '9px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-396px 0',
				left: '10px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-595px 0',
				left: '11px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-792px 0',
				left: '11px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-595px 0',
				left: '11px'
			}, 1).delay(speed).animate({
				backgroundPosition: '-396px 0',
				left: '10px'
			}, 1);
		}
	};
	
	//Bounce! + wobble + fade
	$.fn.bounce = function (bTop1,bTop2,bTop3,bSpeed1,bSpeed2,bSpeed3,wYes,wSpeed,wObject) {
		if(wYes == true){
			$(this).stop().animate({
				top: bTop1 + 'px'
			}, bSpeed1).animate({
				top: bTop2 + 'px'
			}, bSpeed2).animate({
				top: bTop3 + 'px'
			}, bSpeed3).find(wObject).wobble(wSpeed);
		} else {
			$(this).stop().animate({
				top: bTop1 + 'px'
			}, bSpeed1).animate({
				top: bTop2 + 'px'
			}, bSpeed2).animate({
				top: bTop3 + 'px'
			}, bSpeed3);
		}
	};
	
	
	/* home */
	//iMac Animation
	$.fn.iMac = function () {
		$('.imac').stop().animate({
			marginTop: '-210px'
		}, 700).animate({
			marginTop: '-218px'
		}, 200);
		
		$('.imacstand').animate({
			marginTop: '120px'
		}, 700);
		
		
		$('.imacstandshadow').stop().delay(200).animate({
			opacity: 1
		}, 800).animate({
			opacity: '0.8'
		}, 100);
		
		$('.smokeleft').fadeIn(1).stop().delay(120).animate({
			opacity: '0.9',
			marginLeft: '-550px',
			marginTop: '-170px'
		}, 1000).animate({
			opacity: 0,
			marginLeft: '-510px',
			marginTop: '-140px'
		}, 600).fadeOut(1);
		
		$('.smokeright').fadeIn(1).stop().delay(120).animate({
			opacity: '0.9',
			marginRight: '-550px',
			marginTop: '-170px'
		}, 1000).animate({
			opacity: 0,
			marginRight: '-510px',
			marginTop: '-140px'
		}, 600).fadeOut(1);
		
		$('.desktop').stop().hide().delay(800).fadeIn(400);
		
		$('.dock img').stop().delay(1005).animate({
			marginTop: 0
		}, 300);
		
		$('.desktop .coda').stop().animate({
			opacity: 0
		}, 1).delay(2100).animate({
			opacity: '1'
		}, 200);
		
		$('#home .bg').animate({
			opacity: '1'
		}, 700);
	};


	/* Mail */
	// Form
	$.fn.mailForm = function () {
		if ($('#form .letter').hasClass('sel')){
		 	$('#form .letter').removeClass('sel').animate({
		 		bottom: '-500px'
		 	}, 300);
		 	
			$('#form .envelope').delay(140).animate({
		 		bottom: '-500px'
		 	}, 500);
		 	
		 	window.location.hash == '#/Contact/Mail'
		} else {
			$('#form .envelope').animate({
		 		bottom: '-130px'
		 	}, 400).animate({
		 		bottom: '-160px'
		 	}, 100);
		 	
		 	$('#form .letter').delay(100).addClass('sel').animate({
		 		bottom: '100px'
		 	}, 500);
		 }
	};
	
	//Side
	$.fn.mailSide = function () {
		if($('#form .side1').hasClass('sel')){
			$('#form .side1').removeClass('sel').stop().animate({
				width: '281px'
			}, 400);
			
			$('#form .line').stop().animate({
				width: '2px',
				left: '302px'
			}, 400);
		} else {
			$('#form .side1').addClass('sel').stop().animate({
				width: '482px'
			}, 400);
						
			$('#form .line').stop().animate({
				width: '28px',
				left: '500px'
			}, 400);
		}
	};
	
	/* About */
	//3 frames animation
	$.fn.threeframes = function () {
		$('#about #me').animate({
			backgroundPosition: '-220px 0'
		}, 1).delay(100).animate({
			backgroundPosition: '-0px 0'
		}, 1).delay(100).animate({
			backgroundPosition: '-220px 0'
		}, 1).delay(100).animate({
			backgroundPosition: '-440px 0'
		}, 1);
	}
	
	
	
	/* Menu */
	//check previous & next function
	$.fn.pnCheck = function (objSpeed) {
		if(objSpeed == null){
			var objSpeed = '800';
		}
		
		if($('#menu ul li:first').hasClass('sel')){
			$('#menu .left img').fadeOut(objSpeed);
			$('#menu .right img').fadeIn(objSpeed);
		} else if($('#menu ul li:last').hasClass('sel')){
			$('#menu .right img').fadeOut(objSpeed);
			$('#menu .left img').fadeIn(objSpeed);
		} else {
			$('#menu .right img').fadeIn(objSpeed);
			$('#menu .left img').fadeIn(objSpeed);
		}
	};
	
	// Slide to selected item
	$.fn.menu = function (objSpeed) {
	 if($(this).hasClass('sel') == false){
		if(objSpeed == null){ var objSpeed = '800'; }
		
		var thisObj = $(this).removeClass('sel').attr('class');
		if (jQuery.browser.mozilla) {
			if (thisObj == 'mabout'){ var objLeft = '82px'; var pObj = '100%'; }
			else if (thisObj == 'mportfolio'){ var objLeft = '159px'; var pObj = '200%'; }
			else if (thisObj == 'mblog'){ var objLeft = '255px'; var pObj = '300%'; }
			else if (thisObj == 'mcontact'){ var objLeft = '324px'; var pObj = '400%'; }
			else { var objLeft = '5px'; var pObj = '0%'; $('#home').page(); }
		} else {
			if (thisObj == 'mabout'){ var objLeft = '82px'; var pObj = '100%'; }
			else if (thisObj == 'mportfolio'){ var objLeft = '160px'; var pObj = '200%'; }
			else if (thisObj == 'mblog'){ var objLeft = '258px'; var pObj = '300%'; }
			else if (thisObj == 'mcontact'){ var objLeft = '326px'; var pObj = '400%'; }
			else { var objLeft = '2px'; var pObj = '0%'; $('#home').page(); }
		}

		var objWidth = $(this).find('a').width() - 10;
		
		$('#menu .mmenu .msel').stop().animate({
			left: objLeft
		}, objSpeed);
		$('#menu .mmenu .msel .mmiddle').stop().animate({
			width: objWidth + 'px',
			height: '33px'
		}, objSpeed);
		
		
		$('#menu li').removeClass('sel').find('a').animate({
			color: '#000'
		}, 100);
		$(this).addClass('sel').find('a').animate({
			color: '#fff'
		}, 100);
		$(this).pnCheck(objSpeed);
		
		var objSpeed2 = objSpeed / 3 * 4
		
		$('#pages #pageswidth').stop().animate({
			marginLeft: '-' + pObj
		}, objSpeed2)
		
		$('#logo .logoani').wobble(50);
		$('#logo .logoani').wobble(10);
		
		var pageSys = $(this).find('a').attr('href');
		if (pageSys == '#/About'){ $('#about').page();
		} else if (pageSys == '#/Service') { $('#service').page();
		} else if (pageSys == '#/Portfolio') { $('#portfolio').page();
		} else if (pageSys == '#/Blog') { $('#blog').page();
		} else if (window.location.hash == '#/Contact') { $('#contact').page();
		} else { $('#home').page(); }
		
	 } else {
	 	$(this).find('a').css('color', '#fff');
	 	return false;
	 }
	};

	//action previous & next
	$.fn.pnMove = function (objSpeed) {
		if($(this).parent().hasClass('left')){
			if($('#menu ul .sel').prev().find('a').attr('href') == 'undefined'){
				return false;
			} else {
				$('#menu ul .sel').prev().menu();
				var mAchor = $('#menu ul .sel').find('a').attr('href');
				window.location = mAchor
			}
		} else if ($(this).parent().hasClass('right')) {
			if($('#menu ul .sel').next().find('a').attr('href') == 'undefined'){
				return false;
			} else {
				$('#menu ul .sel').next().menu();
				var mAchor = $('#menu ul .sel').find('a').attr('href');
				window.location = mAchor
			}
		} else {
			alert('Problem?');
		}
	};
	
	
	//enter website menu
	$.fn.menuEnter = function () {
		$('#menu').delay(100).animate({
			bottom: '100px'
		}, 600)
	};
	
	$.fn.footerEnter = function () {
		$('#footer').delay(200).animate({
			bottom: 0
		}, 600)
	};
	
	$.fn.footerLeave = function () {
		$('#footer').delay(200).animate({
			bottom: '-88px'
		}, 600)
	};
	
	
	// Portfolio
	$.fn.portfolioPN = function () {
		if($(this).hasClass('previous') == true){
			if($('#portfolio .item:first').hasClass('sel') == true){
				$('#portfolio .item').removeClass('sel');
				$('#portfolio .item:last').addClass('sel');
				$('#portfolio .item:first').addClass('nosel');
			} else {
				$('#portfolio .item.sel').removeClass('sel').addClass('nosel').prev().addClass('sel');
			}
		} else {
			if($('#portfolio .item:last').hasClass('sel') == true){
				$('#portfolio .item').removeClass('sel');
				$('#portfolio .item:first').addClass('sel');
				$('#portfolio .item:last').addClass('nosel');
			} else {
				$('#portfolio .item.sel').removeClass('sel').addClass('nosel').next().addClass('sel');
			}	
		}
		
		if($(this).attr('class') == 'next'){
			var objGo = '-150%'
			var objGo2 = '150%'
		} else {
			var objGo = '150%'
			var objGo2 = '-150%'
		}
		
		$('#portfolio .item.nosel').stop().animate({top: objGo}, 800);
		$('#portfolio .item.sel').stop().animate({top: objGo2}, 1).animate({top: '50%'}, 800);
		
		$('#portfolio .item.sel').portfolioSlide();
		$('#portfolio .item.sel').portfolioRotate();
		
		$('#portfolio .item.nosel').removeClass('nosel');
	};

	$.fn.portfolioSlide = function () {
		$('#portfolio .item.sel .ileft1').stop().delay(700).animate({marginLeft: '-263px'}, 800);
		$('#portfolio .item.sel .iright1').stop().delay(700).animate({marginLeft: '67px'}, 800);
		
		$('#portfolio .item.sel .ileft2').stop().delay(700).animate({marginLeft: '-175px'}, 800);
		$('#portfolio .item.sel .iright2').stop().delay(700).animate({marginLeft: '-20px'}, 800);
		
		$('#portfolio .item.nosel .ileft1, #portfolio .item.nosel .ileft2, #portfolio .item.nosel .iright1, #portfolio .item.nosel .iright2').animate({marginLeft: '-98px'}, 800);
	};
	
	$.fn.portfolioRotate = function () {
		$('#portfolio .item.nosel .rotate180').stop().animate({rotate: '180'}, 800)
		$('#portfolio .item.sel .rotate180').stop().animate({rotate: '-180'}, 1).animate({rotate: '0'}, 780);
	};


	// Tooltip
	$.fn.tooltip = function (inputTxt) {
		var objClass = $(this).attr('class');
		
		if(inputTxt == 'away'){
			$('#tooltip').hide().html('').removeClass(objClass);
		} else {
			$('#tooltip').addClass(objClass).html(inputTxt).show();
		}
	};
		
	
	// About stats
	$.fn.aboutStats = function () {
		var widthps = '180px';
		var widthai = '130px';
		var widthhtml = '200px';
		var widthcss = '200px';
		var widthjs = '160px';
		var widthphp = '50px';
			
		$('.middle').animate({
				width: '1px'
		}, 1);
		
		$('.middle.ps').stop().animate({ width: widthps }, 800);
		$('.middle.ai').stop().animate({ width: widthai }, 800);
		$('.middle.html').stop().animate({ width: widthhtml }, 800);
		$('.middle.css').stop().animate({ width: widthcss }, 800);
		$('.middle.js').stop().animate({ width: widthjs }, 800);
		$('.middle.php').stop().animate({ width: widthphp }, 800);
			
	};
