
$(function () {
	$('.blink')
		.focus(function(){
			$(this).addClass('field-h');
			if( $(this).val() == $(this).attr('title') ) {
				$(this).val('');
			}
		})
		.blur(function(){
			$(this).removeClass('field-h');
			if( $(this).val() == '' ) {
				$(this).val( $(this).attr('title') );
			}
		});
		
	$('#overdrive.paid-user a.overdrive').click(function () {
		$(this).toggleClass('on');
		if ( $(this).hasClass('on') ) {
			$.cookie('overdrive', 'on', { expires: 30, path: '/' }) ;
		} else {
			$.cookie('overdrive', 'off', { expires: 30, path: '/' }) ;
		}
		location.reload() ;
		return false;
	});
	$('#overdrive.free-user').hover(function () {
		$(this).find('.tip').fadeIn();
	}, function () {
		$(this).find('.tip').fadeOut();
	});
	$('#c-head ul.overdrive.paid-user li.on a').click(function () {
		$(this).addClass('active') ;
		$('#c-head ul.overdrive.paid-user li.off a').removeClass('active') ;
		$.cookie('overdrive', 'on', { expires: 30 }) ;
		return false ;
	});
	$('#c-head ul.overdrive.paid-user li.off a').click(function () {
		$(this).addClass('active') ;
		$('#c-head ul.overdrive.paid-user li.on a').removeClass('active') ;
		$.cookie('overdrive', 'off', { expires: 30 }) ;
		return false ;
	});
	
	// home tabs
	var hash = window.location.hash;
	if ( hash == '#create' ) {
		$('#tab-content li').eq(1).show();
		$('#tab-create').addClass('tab-active');
	} else {
		$('#tab-content li').eq(0).show();
		$('#tab-search').addClass('tab-active');
	}
	$('#head .tab').click(function () {
		$('#head .tab').not(this).removeClass('tab-active');
		$(this).addClass('tab-active');
		
		var idx = $('#head .tab').index(this);
		$('#tab-content li').hide().eq(idx).show();
		return false;
	});
	
	// dropdown
	$('.dd > li a').each(function (index) {
		$(this).width($(this).parent().find('ul').width()-40);
	});
	$('.dd .t').click(function () {
		if (!$(this).parent().find('ul').is(':visible')) {
			$('.dd li ul').hide();
			$(this).parents('li').find('ul').slideToggle(200);
		} else {
			$('.dd li ul').hide();
		}
		return false;
	});
	$('.dd li ul li a').click(function () {
		$(this).parent().parents('li').find('.t').html($(this).html()+'<span>&nbsp;</span>');
		$(this).parent().parent().hide();
//		return false;
	});
	$('body').click(function (e) {
		if ($('.dd ul').is(':visible')) {
			$('.dd ul').hide();
			return false;
		}
		if ($('.tooltip, .tooltip2').is(':visible') && !$(e.target).hasClass('t-holder2') && !$(e.target).hasClass('t-holder2-t') && !$(e.target).hasClass('checkbox') && !$(e.target).hasClass('l2') && !$(e.target).hasClass('l4')) {
			$('.tooltip, .tooltip2').hide();
			$('.t-holder2').attr('disabled', false);
			//return false;
		}
	});
	
	// tabs
	var idx = $('.tabs li a').index($('.tabs li a.active'));
	$('.tab-content li').eq(idx).show().addClass('active');
	$('.tabs li a').click(function () {
		var idx = $('.tabs li a').index(this);
		$('.tabs li a').removeClass('active').eq(idx).addClass('active');
		$('.tab-content li').hide().eq(idx).show();
//		return false;
	});
	
	// emots
	$('.emot a').click(function () {
		var val = parseInt($(this).find('span').html())+1;
		$(this).find('span').html(val);
		return false;
	});
	
	// popups
	$('.popup .btn-close').click(function () {
		$('#overlay, .popup').fadeOut();
		return false;
	});
	$('#overlay').click(function () {
		$('#overlay, .popup').fadeOut();
		return false;
	});
	// center
	$('.popup').center();
	
	$('#acc-create').click(function () {
		$('#overlay, .p-reg').fadeIn();
		return false;
	});
	$('#acc-signin').click(function () {
		$('#overlay, .p-login').fadeIn();
		return false;
	});
	$('#video').click(function () {
		$('.p-vid').fadeIn();
		return false;
	});
	$('.btn-like').click(function () {
		$('#overlay, .p-fav').fadeIn();
//		return false;
	});
	
	// focus
	$('.links .field, .form1 .field').focus(function () {
		$(this).select();
	});
	
	// caption
	$('.btn-save').click(function () {
		$('.box-caption p').html($(this).parents('form').find('textarea').attr('value')).parents('.box-caption').slideDown();
		return false;
	});
	
	// upgrade
	$('.form-a .field').focus(function () {
		$(this).addClass('field-h');
	}).blur(function () {
		$(this).removeClass('field-h');
	});
	
	// tooltip
	$('.t-holder .checkbox').click(function () {
		$('.tooltip').css({top: $(this).position().top-60, left: $(this).position().left+$(this).width()/2-$('.tooltip').width()/2}).show();
		return false;
	});
	$('.t-holder2-t').click(function () {
		$(this).blur();
		$('.tooltip').css({top: $(this).position().top-60, left: $(this).position().left+$(this).width()/2-$('.tooltip').width()/2}).show();
	});
	$('.t-holder2').mousedown(function () {
		$(this).attr('disabled', true);
		$('.tooltip').css({top: $(this).position().top-60, left: $(this).position().left+$(this).width()/2-$('.tooltip').width()/2}).show();
		return false;
	});
});
