var charts = new Array();
$(document).ready(function(){
	$("#searchstripe").click(function(){
		$stripelink = $(this);
		if($stripelink.children("i").is(".min")) {
			if ($stripelink.children("span").text() == "Minimize")
				$stripelink.children("span").text("Expand");
			else if ($stripelink.children("span").text() == "Минимизировать")
				$stripelink.children("span").text("Развернуть");
			else if ($stripelink.children("span").text() == "Minimizar")
				$stripelink.children("span").text("Expandir");
			else if ($stripelink.children("span").text() == "最小化")
				$stripelink.children("span").text("展开");
			$stripelink.children("i").removeClass("min").addClass("exp");
			var idEl = document.getElementById("searchline"); 
			var idEl2 = document.getElementById("keyword_string"); 
			idEl.value = idEl2.value;
			idEl2.value = "";
			var idEl3 = document.getElementById("current_form"); 
			idEl3.value = "stripe";
		} else {
			if ($stripelink.children("span").text() == "Expand")
				$stripelink.children("span").text("Minimize");
			else if ($stripelink.children("span").text() == "")
				$stripelink.children("span").text("஢");
			else if ($stripelink.children("span").text() == "Expandir")
				$stripelink.children("span").text("Minimizar");
			else if ($stripelink.children("span").text() == "??")
				$stripelink.children("span").text("???");
			$stripelink.children("i").removeClass("exp").addClass("min");
			var idEl = document.getElementById("searchline"); 
			var idEl2 = document.getElementById("keyword_string"); 
			idEl2.value = idEl.value;
			idEl.value = "";
			var idEl3 = document.getElementById("current_form"); 
			idEl3.value = "full";
		}
		$("#searchline").toggle();
		$("#searchform").slideToggle();
	});
	$("div[id^='lever-'] .hlink").click(function(){
		$clicked = $(this);
		$levered = $clicked.parent().attr("id").split("-");
		$object = $("#"+$levered[1]);
		if ($clicked.parent().is(".checkboxes")) {
			if ($clicked.is(".do")) $object.find(":checkbox").prop("checked","checked");
			else $object.find(":checkbox").prop("checked","");
		} else if ($clicked.parent().is(".options")){
			if ($clicked.is(".do")) $object.find("option").prop("selected","selected");
			else $object.find("option").prop("selected","");
		}
	});
	if ($("a.fancymodal").length) $("a.fancymodal").fancybox({'modal':true});
	$(".closeshady .hlink").click(function(){
		$.fancybox.close();
	});
	$(".hlink").bind("mouseover mouseout", function(){
		$(this).toggleClass("hover");
	});
	$(".hoverlight td").bind("mouseover mouseout", function(){
		$(this).parent().toggleClass("hover");
	});
	val1 = "Money";
	val2 = "Risk";
	$("span.swapnum").click(function(){
		t1 = $("#swap1").text();
		t2 = $("#swap2").text();
		$clicked = $(this);
		if ($clicked.is(".num2")) $clicked.removeClass("num2").addClass("num1").text("Swap with "+val2);			
		else $clicked.removeClass("num1").addClass("num2").text("Swap with "+val1);
		$("#swap1").text(t2);
		$("#swap2").text(t1);
	});
	if ($("table.maintype-tbl").length) $("body").append('<div id="tipbox" class="shadytip"><span id="tipplace"></span></div>');
	$("table.maintype-tbl td").unbind().bind("mouseover", function(e) {
		$table = $(this).parents("table.maintype-tbl");
//		if ($table.is(".nohover")) {
		if ($(this).parents().is(".nohover")) {
			$("#tipplace").text("");
			$("#tipbox").hide();
			return;
		} else {	
			$(this).addClass("hover");
			$n = $(this).index();
			if ($table.is(".doubleth")) $txt = $table.find(".th"+$n).html();
			else $txt = $table.find("th:eq("+$n+")").html();
			this.top = e.pageY+25;
			this.left = e.pageX+15;
			$("#tipplace").html($txt);
			$("#tipbox").css("top", this.top+"px").css("left", this.left+"px").show();
			if ($("#tipplace").text()=="") $("#tipbox").hide();
		}
	}).bind("mousemove", function(e) {
		this.top = e.pageY+25;
		this.left = e.pageX+15;
		$("#tipbox").css("top", this.top+"px").css("left", this.left+"px");
	}).bind("mouseleave", function(e) {
		$(this).removeClass("hover");
		$("#tipbox").hide();
	});
	$("table.maintype-tbl th").unbind().bind("mouseover", function(e) {
		if ($(this).parents().is(".notip")) {
			$("#tipplace").text("");
			$("#tipbox").hide();
			return;
		} else if ($(this).children(".thtip").length) {
			$txt = $(this).children(".thtip").html();
			if ($txt!="") {
			//console.log($txt);
				this.top = e.pageY+25;
				this.left = e.pageX+15;
				$("#tipplace").html($txt);
				$('#tipbox').css("top", this.top+"px").css("left", this.left+"px").show();
			}			
		}
	}).bind("mousemove", function(e) {
		this.top = e.pageY+25;
		this.left = e.pageX+15;
		$("#tipbox").css("top", this.top+"px").css("left", this.left+"px");
	}).bind("mouseleave", function(e) {
		$(this).removeClass("hover");
		$("#tipbox").hide();
	});
	$("p[id^='to-']").bind("mouseenter", function(){
		$object = $(this);
		$object.addClass("overmarked");
		$splited = $object.attr("id").split("-");
		$("#"+$splited[2]).children("div."+$splited[1]).addClass("up").siblings("div:not(."+$splited[1]+")").addClass("down");
	}).bind("mouseleave", function(){
		$("#"+$splited[2]).children("div").removeClass("up").removeClass("down");
		$object.removeClass("overmarked");
	});
	$("div.dot").bind("mouseenter", function(){
		$dot = $(this);
		$dotbox = $dot.parent().attr("id");
		$dotpoint = $dot.attr("class").split(" ");
		$dot.addClass("up").siblings("."+$dotpoint[1]).addClass("up");
		$dot.siblings("div:not(."+$dotpoint[1]+")").addClass("down");
		if ($dot.is("."+$dotpoint[1])) {
			$("#to-"+$dotpoint[1]+"-"+$dotbox).addClass("overmarked");
		}
	}).bind("mouseleave", function(){
		$(".mockup .overmarked").removeClass("overmarked");
		$dot.removeClass("up").siblings().removeClass("up").removeClass("down");
	});
	$("span.mockup-lever").click(function(){
		if ($(this).is(".opened")) return;
		$object = $(this);
		$object.parent().siblings("div.mockup").siblings("div.mockup").slideUp(300).children("div.mockup-dots").hide();
		$object.addClass("opened").parent().next("div.mockup").slideDown(300, function(){
			$object.parent().next("div.mockup").children("div.mockup-dots").show();
		});
		$object.parent().siblings("h2").children("span.hlink").removeClass("opened");		
	});
	$("ul.menulist > li").bind("mouseenter", m_open).bind("mouseleave", m_timer);
	$("ul.dropdown > li").bind("mouseenter mouseleave", function(){$(this).toggleClass("over");});
	
	/* analyzer */
	$(".tablink").click(function(){
		$(".tablink.current").removeClass("current");
		$tablink = $(this);
		$tablink.addClass("current");
		id = $tablink.attr("href");
		$(id).removeClass("invis").siblings(".tabbox").addClass("invis");
		$tablink.blur();
		return false;
	});	
	$(".gettip").bind("mouseenter",function(){
		$tiplink = $(this);
		tipbody = $tiplink.attr("title");
		$tiplink.attr("title","")
	}).bind("click",function(){		
		$("#tipbox").addClass("wtip");
		$("#tipplace").html(tipbody);
		$("#tipbox").show();
		return false;
	}).bind("mouseleave", function(){
		$("#tipbox").removeClass("wtip");
		$tiplink.attr("title",tipbody);
	});
	$(".icontip").bind("mouseover", function(){
		$(this).addClass("pressed");
		$tippoint = $(this);
		i = $tippoint.attr("title");
		$tippoint.attr("title","");
		x = $tippoint.offset().left;
		y = $tippoint.offset().top+24;
		$("#tipplace").html(i);
		$("#tipbox").addClass("wtip").css({left:x,top:y}).show();
	}).bind("mouseout", function(){
		$(this).removeClass("pressed");
		$("#tipbox").hide().removeClass("wtip");
		$("#tipplace").html("");
		$tippoint.attr("title",i);
	}).bind("click",function(){return false;});
	$(".menu-sort.instant .hlink").click(function(){
		$l = $(this);
		$menusort = $l.parents(".menu-sort");
		box = $($l.attr("href"));
		$menusort.addClass("activated");
		$menusort.next(".header").addClass("active");
		if($l.hasClass("current")) {
			$menusort.removeClass("activated");
			$menusort.next(".header").removeClass("active");
			$l.removeClass("current");
			box.slideUp();
		} else {
			$l.addClass("current").siblings(".current.hlink").removeClass("current");
			box.slideDown().siblings(".msort").slideUp();
		}
		return false;
	});
	$(".sortheader .header .hlink").click(function(){
		$header = $(this).parent();
		$menusort = $header.prev(".menu-sort");
		if (!$(this).parent().prev(".menu-sort").is(".activated")) {
			boxid = $(this).attr("href");
			$currentlink = $menusort.find("a[href="+boxid+"]");
			// actions:
			$header.addClass("active");
			$menusort.addClass("activated");
			$currentlink.addClass("current");
			$(boxid).slideDown();
		} else {
			$currentlink = $menusort.find(".hlink.current");
			boxid = $currentlink.attr("href");
			// actions:
			$header.removeClass("active");
			$menusort.removeClass("activated");
			$currentlink.removeClass("current");
			$(boxid).slideUp();
		}
		return false;
	});
	$(".hlink.toggleit").click(function(){
		bid = $(this).attr("href");
		$(this).toggleClass("on");
		$(bid).slideToggle();
		return false;
	});
	$(".sortheader").bind("mouseenter", function(){
		$menusort = $(this).children(".menu-sort");
		$menusort.removeClass("deact");
	}).bind("mouseleave", function(){
		if (!$menusort.is(".activated")) $menusort.addClass("deact");
	});
	$(".charthead .hlink").click(function(){
		$head = $(this).parent();
		$box = $($(this).attr("href"));
		$head.toggleClass("active");
		$box.toggle();
		if (!$(this).hasClass("on")) {
			$href_split = $(this).attr("href").split("-");
			$chart_num = $href_split[2];
			if ($chart_num != 0)
			{
				charts[$chart_num] = new Highcharts.Chart(options[$chart_num]);
			}
			$(this).addClass("on");
		}
	});
	// charts are "on" only after you click the tab
	$(".chartslouncher").click(function(){
		if (!$(this).hasClass("on")) {
			charts[0] = new Highcharts.Chart(options[0]);
/*			var chart1 = new Highcharts.Chart(options1);
			var chart2 = new Highcharts.Chart(options2);
			var chart3 = new Highcharts.Chart(options3);
			var chart4 = new Highcharts.Chart(options4);
			var chart5 = new Highcharts.Chart(options5);*/
			$(this).addClass("on");
		}
	});
	/* // analyzer */
});
$(window).resize(function(){
	
});
var timeout = 500;
var closetimer = null;
var dropbox = null;
function m_open(){
	m_item = $(this);
	m_canceltimer();m_close();
	m_item.addClass("droped");
	dropbox = m_item.children(".dropdown")
	dropbox.css('left',20+m_item.children("a:first-child").width()).show();
}
function m_close(){
	if(dropbox) {
		m_item.siblings().removeClass("droped");
		dropbox.hide();
	}
}
function m_timer(){
	closetimer = window.setTimeout(m_close, timeout);
}
function m_canceltimer(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
