/**
* We use the initCallback callback
* to assign functionality to the controls
*/
Cufon.replace('h1,h2');

jQuery.easing['BounceEaseOut'] = function (p, t, b, c, d) {
    if ((t /= d) < (1 / 2.75)) {
        return c * (7.5625 * t * t) + b;
    } else if (t < (2 / 2.75)) {
        return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
    } else if (t < (2.5 / 2.75)) {
        return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
    } else {
        return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
    }
};


$(function () {
    $('.nav-dropdown').each(function () {
        $(this).find('.tab-list-container li a').click(function () {
            $nav = $(this).parents('.nav-dropdown:first');
            $nav.find('.tab-list-container li').removeClass('selected');
            $(this).parent().addClass('selected');
            $rel = $(this).attr('rel');
            $nav.find('.tab-container').hide();
            if ($rel)
                $($rel).show();

            return false;
        });
    });

    $current_menu = null;
    $('#menu > li > a').hover(function () {
        $rel = $(this).attr('rel');

        if ($current_menu)
            hide_menu($current_menu);

        if (!$rel) return;

        $current_menu = $($rel);

        $current_menu.appendTo($(this).parent());

        center_menu_at($current_menu, $(this).parent());

        return false;
    }, function () {
    });

    $('#menu').hover(function () { }, function () {
        if ($current_menu)
            hide_menu($current_menu);
    });

    function hide_menu($menu) {
        $menu.css('left', -5000);
    }

    function center_menu_at($menu_popup, $dock_i) {
        $padding_left = $('#menu').offset().left;
        $padding_right = $padding_left + $('#menu').width();

        $top = $dock_i.offset().top + $dock_i.outerHeight();
        $w = $menu_popup.width();

        $left = $dock_i.offset().left;
        $padding = 10;

        if ($left + $w >= $padding_right)
            $left = $padding_right - $w - $padding - $dock_i.width() / 2;

        $menu_popup.css('top', $top).css('left', $left);
    }
});

$(document).ready(function () {

    $('#textareacomment').elastic();
    $("ul.top-menu").superfish();
    $("ul.sf-menu").superfish();
//    $("#register").colorbox({ width: "694px;", inline: true, href: "#reg" });
//    $("#login").colorbox({ width: "250px;", inline: true, href: "#log" });
//    $("#sendmessage").colorbox({ width: "694px;", inline: true, href: "#send" });



    $(".window .close").click(function () {
        $(this).parents(".window").animate({ opacity: "hide" }, "slow");
    });

    $(".mail .close2").click(function () {
        $(this).parents(".mail").animate({ opacity: "hide" }, "slow");
    });

    	//tabs
	$(".tab_content").hide(); 
	$("ul.tabs li:first").addClass("active").show(); 
	$(".tab_content:first").show(); 	
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); 
		$(this).addClass("active"); 
		$(".tab_content").hide(); 
		var activeTab = $(this).find("a").attr("href"); 
		$(activeTab).fadeIn(); 
		return false;
	});
	
	$('#texttab').click(function() {		
		$(".tab_content").addClass("heightone");	
		$(".tab_content").removeClass("heighttwo");
		$(".tab_content").removeClass("heightthree");
		$('#tabscontainer').addClass("hone");	
		$('#tabscontainer').removeClass("htwo");
		$('#tabscontainer').removeClass("hthree");	
	});
	
	$('#imagetab').click(function() {		
		$(".tab_content").addClass("heighttwo");	
		$(".tab_content").removeClass("heightone");
		$(".tab_content").removeClass("heightthree");
		$('#tabscontainer').addClass("htwo");	
		$('#tabscontainer').removeClass("hone");
		$('#tabscontainer').removeClass("hthree");
		$(".tab_container").css("height","650px");
	});
	
	$('#linktab').click(function() {		
		$(".tab_content").addClass("heightthree");	
		$(".tab_content").removeClass("heighttwo");
		$(".tab_content").removeClass("heightone");	
		$('#tabscontainer').addClass("hthree");	
		$('#tabscontainer').removeClass("htwo");
		$('#tabscontainer').removeClass("hone");	
	});



    $().ready(function () {
        swapValues = [];
        $(".wm").each(function (i) {
            swapValues[i] = $(this).val();
            $(this).focus(function () {
                if ($(this).val() == swapValues[i]) {
                    $(this).val("").removeClass("watermark")
                }
            }).blur(function () {
                if ($.trim($(this).val()) == "") { $(this).val(swapValues[i]).addClass("watermark") } 
            })
        })
    });

  	$(".fantateinp").elastic();
  	$(".fantateinp").trigger('update');
});
