// CUSTOM SCRIPT by iKarina & iGor - http://themeforest.net/user/iKarina
$(function(){
	// HOVER ANIMATION FOR PORTFOLIO #3 TEMPLATE
	$('img.pf3link').mouseenter(function(){
		$(this).stop(true, false).animate({ opacity: "1" }, 200)
	})
	$('img.pf3link').mouseleave(function(){
			$(this).stop(true, true).animate({ opacity: "0.01" }, 200, fix);
			function fix() {
				if ($('img.pf3link').mouseleave) {
					$(this).animate({ opacity: "0.01" }, "fast")
				}
			}
	})
	// ANIMATED TOOLTIPS
	$(".tooltip").mouseenter(function(){
		var tt_title = $(this).attr("title");
		if (tt_title) {
			var tt_id = 'tt_id' + Math.floor(Math.random()*999);
			$(this).attr('title','');
			$("body").append('<div id="' + tt_id + '" class="tt_wrap"><div class="ttbox"><span>' + tt_title + '</span></div></div>');
			offset = $(this).offset();
			width = $(this).outerWidth() / 2;
			tt_left = offset.left - 90 + width;
			tt_top = offset.top - 250;
			tt_wrap_id = '#' + tt_id;
			var tt_box_id = tt_wrap_id + '> div';
			$(tt_wrap_id).css({left: tt_left, top: tt_top});
			$(tt_box_id).css({bottom:15, opacity:0}).animate({bottom:5, opacity:1}, 300);
		}
		$(this).mouseleave(function(){
			$(tt_box_id).stop().animate({bottom:30, opacity:0}, 300, rem);
				function rem() {
					$(this).parent().remove();
				}
			$(this).attr('title',tt_title);
		})
	})
	// NOTES SHORTCODE
	$('.die').click(function(){
		id = $(this).parent().parent().attr('id');
		h = $('#'+id+'>div').outerHeight(true);
		$('#'+id).css('height',h);
		$(this).remove();
		$('#'+id).find('.nt').animate({opacity:0},'fast', function(){
			h = $(this).parent().innerHeight();
			$(this).parent().css('height',h);
			$(this).remove();
			$('#'+id+'>div').animate({width:0},'fast', function(){
				$(this).remove();
				$('#'+id).animate({height:0},'fast', function(){
					$(this).remove();
				})
			})
		})
	})
	// TAGS TABS WIDGET
	$('div#flowpanes7 ul#widget-list-tags a').append('<span>&nbsp;</span>');
	$('div.tagcloud a').append('<span>&nbsp;</span>');
	// CFORM FIXING
	$('.cformpanda').find('.your-name input').val('Name');
	$('.cformpanda').find('.your-email input').val('Email');
	$('.cformpanda').find('.your-message textarea').val('Message');
	// MENU ROUNDED CORNERS for default WP3 menu
	$('div.menu ul ul li:last-child').addClass('li-last');
	$('div.menu ul ul ul li:first-child').addClass('li-first');
	$('div.menu ul ul ul li:last-child').addClass('li-last');
	$('div.menu ul ul').prev().addClass('a-level');
	$('div.menu ul ul ul').prev().removeClass('a-level');
	// MENU ROUNDED CORNERS for custom WP3 menu
	$('ul.menu ul li:last-child').addClass('li-last');
	$('ul.menu ul ul li:first-child').addClass('li-first');
	$('ul.menu ul ul li:last-child').addClass('li-last');
	$('ul.menu ul').prev().addClass('a-level');
	$('ul.menu ul ul').prev().removeClass('a-level');
	// MEGAMENU POSITION
	$('ul.megamenu').css('left', megaindent);
	$('li.basic-mega > ul').css('left', megaindent);
	function megaindent() {
			position = $(this).parent().position();
			left = position.left;
			return -left;
	}
});
