/*!
 * Color animation jQuery-plugin
 * http://www.bitstorm.org/jquery/color-animation/
 * Copyright 2011 Edwin Martin <edwin@bitstorm.org>
 * Released under the MIT and GPL licenses.
 */
(function(d){function i(){var b=d("script:first"),a=b.css("color"),c=false;if(/^rgba/.test(a))c=true;else try{c=a!=b.css("color","rgba(0, 0, 0, 0.5)").css("color");b.css("color",a)}catch(e){}return c}function g(b,a,c){var e="rgb"+(d.support.rgba?"a":"")+"("+parseInt(b[0]+c*(a[0]-b[0]),10)+","+parseInt(b[1]+c*(a[1]-b[1]),10)+","+parseInt(b[2]+c*(a[2]-b[2]),10);if(d.support.rgba)e+=","+(b&&a?parseFloat(b[3]+c*(a[3]-b[3])):1);e+=")";return e}function f(b){var a,c;if(a=/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/.exec(b))c=
[parseInt(a[1],16),parseInt(a[2],16),parseInt(a[3],16),1];else if(a=/#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/.exec(b))c=[parseInt(a[1],16)*17,parseInt(a[2],16)*17,parseInt(a[3],16)*17,1];else if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(b))c=[parseInt(a[1]),parseInt(a[2]),parseInt(a[3]),1];else if(a=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([01\.]*)\s*\)/.exec(b))c=[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10),parseFloat(a[4])];return c}
d.extend(true,d,{support:{rgba:i()}});var h=["color","backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","outlineColor"];d.each(h,function(b,a){d.fx.step[a]=function(c){if(!c.init){c.a=f(d(c.elem).css(a));c.end=f(c.end);c.init=true}c.elem.style[a]=g(c.a,c.end,c.pos)}});d.fx.step.borderColor=function(b){if(!b.init)b.end=f(b.end);var a=h.slice(2,6);d.each(a,function(c,e){b.init||(b[e]={a:f(d(b.elem).css(e))});b.elem.style[e]=g(b[e].a,b.end,b.pos)});b.init=true}})(jQuery);



$(function(){
	$('#fly').find('.airplane')
		.mouseover(function(){
			$('#fly').find('.banner')
				.animate({left:15},300)
				.animate({left:0},150);
		})
		.click(function(){
			$('#fly').find('.banner')
				.animate({left:parseInt($('#fly').width()/2+500)},1000,function(){
					$(this)
						.css({left:-parseInt($('#fly').width()/2+1200)})
						.delay(500)
						.animate({left:0},1500);
				});
		});
	
	$('.input-label-placeholder input').focusin(function(){
		if ($(this).val() == '') {
			$(this).parent().find('label').fadeOut(100);
		};
	}).focusout(function(){
		if ($(this).val() == '') {
			$(this).parent().find('label').fadeIn(100);
		};
	});
	
	$('.logged-in .more a').click(function(){
		//$('.logged-in').toggleClass('logged-in-actions').find('ul').slideToggle(200);
		lin = $('.logged-in');
		linul = lin.find('ul');
		if (!linul.is(':animated')) {
			if (!lin.hasClass('logged-in-actions')) {
				lin.addClass('logged-in-actions').height(lin.height()).animate({borderColor:'#d1e0e0',height:'+='+linul.height(),marginBottom:32},200)
				linul.fadeIn(400);
			} else {
				lin.removeClass('logged-in-actions').height(lin.height()).animate({borderColor:'#fff',height:'-='+linul.height(),marginBottom:10},400)
				linul.fadeOut(200);
			};
		};
		return false;
	});
	
	/*$('.mainMenu a').hover(function(){
		$(this).parents('li').addClass('hover');
	},function(){
		$(this).parents('li').removeClass('hover');
	});*/
	
	$('a.hint-link').each(function(){
		$(this).attr('data-title',$(this).attr('title'));
		$(this).removeAttr('title');
	});
	$('a.hint-link').hover(function(){
		hint = $('<div><b></b><span></span></div>')
			.addClass('hint')
			.appendTo('body');
		
		hint.find('span').text($(this).attr('data-title'));
		hint
			.css({
				opacity:0,
				left:$(this).offset().left-19,
				top:($(this).offset().top-hint.outerHeight()-30)
			})
			.show();
		
		hint.animate({
			opacity:1,
			top:'+='+15
		},200)
	},function(){
		hint.fadeOut(200,function(){ $(this).remove(); });
	});
	
	// select box
	$('.selectInput').click(function(){
		si = $(this);
		$('.selectInput-focus').not(si).each(function(){
			$(this).removeClass('selectInput-focus'); // close previously opened
		});
		if (si.hasClass('selectInput-focus')) {
			si.removeClass('selectInput-focus');
			$(document).unbind('click',hideSelectMenu);
		} else {
			si.addClass('selectInput-focus');
			$(document).bind('click',hideSelectMenu);
		};
	});
	
	/*.hover(function(){
		$(this).addClass('selectInput-hover')
	},function(){
		$(this).removeClass('selectInput-hover')
	});*/
	
	$('.selectInput li').click(function(){
		val = $(this).attr('id');
		si = $(this).parents('.selectInput');
		si.find('input').val(val);
		si.find('.selectInput-item').text($(this).text());
		if (si.attr('data-placeholder') == val) {
			si.find('.selectInput-item').addClass('selectInput-item-placeholder');
		} else {
			si.find('.selectInput-item').removeClass('selectInput-item-placeholder');
		};
		si.find('li').removeClass('selectInput-active');
		$(this).addClass('selectInput-active');
	});
	
	function hideSelectMenu(e) {
		target = $(e.target);
		if (target.hasClass('selectInput') || target.parents('.selectInput').length) {
		} else {
			$('.selectInput').removeClass('selectInput-focus');
			$(document).unbind('click',hideSelectMenu);
		};
	};
});
