$(function(){
	
	var logoM = $('.logo_M.home');
	var logo = $('#logo');
	
	$('.word').animate({ opacity: 0, 'padding-top': '380px' }, 0);
	$('#logo_L_title').animate({ opacity: 0, 'margin-top' : '50px' }, 0);
	$('.logo_L').animate({ opacity: 0, 'margin-top' : '100px' }, 0);
	$('#nav.home').animate({ opacity: 0}, 0);
	
	$(document).ready(function() {
		$('#ajaxLoader').addClass('loaded').delay( 300 ).animate({ opacity: 0}, 300);
		$('#container').removeClass('hidden');
		$('.word').each(function(idx) {
		    $(this).animate({ opacity: 1, 'padding-top': '342px' }, 2000, 'easeOutCubic', function(){
				$('#logo_L_title').animate({ opacity: 1, 'margin-top' : '0px'}, 600);
				$('.logo_L').delay( 300 ).animate({ opacity: 1, 'margin-top' : '0px'}, 600, function(){
					$('#nav.home').animate({ opacity: 1}, 600, function(){
						$('.word,#logo_L_title,.logo_L,#nav,.link_description,.link_title').css( "opacity","none" );
					});
				});
			});
		});
	});
	
	// Scroll Process
	$(window).scroll(function(e){
		
		var w = $(this).scrollTop();
		var w_height = $(window).height() - 300;
		
		$(".scroll").each(function() {
			
			var iconS1 = $(this).offset().top - w_height;
		    var iconS2 = $(this).offset().top + $(this).height();
		
			if(w > iconS1) {
				$(this).addClass("active");
			} else {
				$(this).removeClass("active");
			};     
	  	});

			
	});

	// Scroll to main
	scrollToMain = function(pageName) {
		$('#container').animate({marginTop: '-460px'}, 300, function(){
			$('html,body').animate({scrollTop: $('body').offset().top}, 300);
		});
		$("#nav").children().each(function() {
			if ($(this).find('a').attr("id") == pageName) {
				$(this).removeClass("inactive");
				$(this).addClass("active");
			} else {
				$(this).addClass("inactive");
				$(this).removeClass("active");
			}
		});
		$('#header').addClass('invisible');
		$('#footer').removeClass('hidden');
		$('#nav').animate({ opacity: 1}, 400, function(){
			$('#nav').css( "opacity","none" );
		});
		
		$('.logo_M').removeClass('close');
	};
	
	$('.logo_M').live('click', function(){
		$('#container').animate({marginTop: '0px'}, 300);
		$('#header').removeClass('invisible');
		$('#footer').addClass('hidden');
		$('.logo_M').addClass('close');
		$("#nav").children().each(function() {
			$(this).addClass("inactive");
			$(this).removeClass("active");
		});
	});
	
	$('#screen_laptop').live('click', function(){
		$('html,body').animate({scrollTop: $("#screen_section").offset().top - 40}, 300);
	});

	
	// Form labels
	$("label.inlined + .input-text").live('focus', function(){
		$(this).prev("label.inlined").addClass("focus");
		if(!$(this).val() == ""){
			$(this).prev("label.inlined").addClass("has-text").removeClass("focus");
		}
	});

	$("label.inlined + .input-text").live('keypress', function(){
		$(this).prev("label.inlined").addClass("has-text").removeClass("focus");
		clearInterval();
	});

	$("label.inlined + .input-text").live('blur', function(){
		if($(this).val() == ""){
			$(this).prev("label.inlined").removeClass("has-text").removeClass("focus");
		}
		clearInterval();
	});
	
	//textarea expand
	$(".form_message").live('focus', function(){
		$(this).animate({ height: 200 }, 300);
	});
	
	$(".form_message").live('blur', function(){
		if($(this).val() == ""){
			$(this).animate({ height: 144 }, 300);
		}
	});
	
	// Plus buttons
	$('.togglePlus').live('click', function(e){
		if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }
		var target = $(this).attr("href");
	    if ($(this).hasClass('open')){
	    	if($('.togglePlus').hasClass('open')){
				$('.togglePlus').parent().prev().find('.icon').removeClass('active');
			};
			$(this).prev('.plus').slideDown(300);
			$(this).removeClass('open').addClass('close');
			$(this).find('.state_2').removeClass('hidden');
			$(this).find('.state_1').addClass('hidden');
			$(this).parent().prev().find('.icon').addClass('active');
		}else if($(this).hasClass('close')){
			$(this).prev('.plus').slideUp(300);
			$(this).removeClass('close').addClass('open');
			$(this).find('.state_2').addClass('hidden');
			$(this).find('.state_1').removeClass('hidden');
			$(this).parent().prev().find('.icon').removeClass('active');
			$(this).parent().find("a.thumb").removeClass("active");
		}
	});

	
	// Screens preview
	$("a.thumb").live('click', function(e){
		e.preventDefault();
		$("a.thumb").removeClass("active");
		$(this).addClass("active");
		var title = this.title;
		var rel = this.rel;
		var caption = (this.title != "") ? "<br/>" + this.title : "";
		$("#previewTarget").html("");
		$("#previewParagraph h4").html("");
		$("#previewParagraph p").html("");
		$("#previewTarget").append("<img src='"+ this.href +"' alt='Image preview' />");
		$("#previewParagraph h4").append(title);
		$("#previewParagraph p").append(rel);
		$("#preview").slideDown(300);
		$("#toggle_preview").removeClass('open').addClass('close');
		$("#toggle_preview").find('.state_2').removeClass('hidden');
		$("#toggle_preview").find('.state_1').addClass('hidden');
		$("#toggle_preview").parent().prev().find('.icon').addClass('active');
    });
	
	$('.btn_screen').live('mouseenter', function() {
		$('#screen_topcty').animate({backgroundPositionY:0}, 300);
	});
	
	$('.btn_screen').live('mouseleave', function() {
		$('#screen_topcty').animate({backgroundPositionY:35}, 300);
	});

	// Btn states
	$('.btn_radio .button').live('click', function(e){
		e.preventDefault();
		$('.btn_radio .button').removeClass('active');
		$(this).addClass('active');
		$(this).prev('input[type=radio]').attr('checked', 'checked'); ;
	});
		
});

