$(document).ready(function () {
	setMainNav();						
	setAccordion();
});

function setMainNav(){
	var bgX = Array(-31 , 58, 189 , 324);
	$("#big-dot span").hide();
	$("#nav-main li a").mouseover(function(){
		if($(this).attr("class") == "nav-noactive"){
			hideSubNav();
			var pos = Number($(this).attr("tabindex"));
			$(this).attr("class","nav-active");
			$(this).parent().parent().css({ "background-position": bgX[(pos - 1)]+"px" + " "+ (-(pos - 1)*55)+"px"});
			var id = "sub" + $(this).attr("id");
			$(this).css({ "color": "#c80000" });
			if($(this).parent().attr("class") == "expand-nav"){
				showSubNav(id,pos);
			}
		}
	});
	$("#nav-main li a").mouseout(function(){
		if($(this).attr("class") == "nav-active" && $(this).parent().attr("class") == "expand-nav"){
			$(this).css({ "color": "#c80000" });
		}else {
			$(this).parent().parent().css({ "background-position": "-500px 0px"});
			$(this).attr("class","nav-noactive");
			$("#nav-main li a").css({ "color": "white" });
		}
	});
	$("#network-link").bind('click' ,function(){
		showNetWork();
		return false;
	});
	$("#header .container .box-dx").mouseleave(function(){
		$("#nav-main").css({ "background-position": "-500px 0px"});					  
		hideSubNav();				  
	});
}

function showNetWork(){
	/* -------------------------------------------------------------------------------- */
	$('#map-network').load('http://localhost:8888/rc/network.html', function() {
		$('#map-network').css({"display":"block"});
	  	$(this).stop().animate({ "margin-top":"0px"}, {duration:500});
		setNetWork();
	});
}

function setNetWork(){
	$("#network-link").unbind('click');
	$("#closer-network").click(function() {
		closeNetwork();
		return false;
	});
	$(".dot-office").mouseover(function(){
		showOfficeInfo($(this).attr('id'));
		
	});

}

function showOfficeInfo(id){
	//$("#" + id + "-info").show("drop", { direction: "right" }, 400);
	$(".network-info").hide();
	$("#" + id + "-info").show("drop", { direction: "right" }, 200);
}

function closeNetwork(){
	$('#map-network').stop().animate({ "margin-top":"-446px"}, {duration:500});
	$("#network-link").bind('click' ,function(){
		showNetWork();
		return false;
	});
}



function showSubNav(id,pos){
	var bgX = Array(41, 0, 257 , 0);
	$("#" + id).show("drop", { direction: "left" }, 500);
	$("#big-dot span").css({"margin-left":bgX[pos - 1] +"px", "margin-top": "-5px"});
	$("#big-dot span").hide();
	$("#big-dot span").show("drop", { direction: "up" }, 500);
}

function hideSubNav(){
	$("#nav-main li a").css({ "color": "white" });
	$("#nav-main li a").attr("class","nav-noactive");
	$(".nav-sub ul").fadeOut("fast");
	$("#big-dot span").fadeOut("fast");
}


function setAccordion(){
	$(".container-accordion h4").mouseover(function(){
		if($(this).attr("class") == "corner-all no-active"){
			$(this).css({ "cursor":"pointer", "background-color":"#c80000" });
		}											 												 
	});
	$(".container-accordion h4").mouseout(function(){
		if($(this).attr("class") == "corner-all no-active"){
			$(this).css({"background-color":"#f1414b" });	
		}											 												 
	});
	$(".container-accordion h4").click(function(){
		if($(this).attr("class") == "corner-all no-active"){
			var id = $(this).parent().parent().attr("id");
			openAccordion(id);
		}
	});
	openAccordion("people-oriented-tv");
}
function openAccordion(id){
	var marginGap = 0;
	$('.accordion-people-oriented').each(function(index){
		var checkid = $(this).attr('id');
		if($(this).attr('id') == id){
			var gap = index * 41;
			marginGap = 259;
			$("#" + id).stop().animate({"width":"299px","margin-left": gap + "px"}, {duration:500});
			var classHead = $("#" + id).children(".container-accordion").children("h4").attr("class");
			$("#" + id).children(".container-accordion").children("h4").removeClass(classHead).addClass('corner-all active');
			$("#" + id).children(".container-accordion").children("h4").css({"color":"#c80000", "background":"white"});
		}else{		
			var gap = (index * 41) + marginGap;
			$("#" + checkid).stop().animate({"width":"40px","margin-left":gap + "px"}, {duration:500});
			var classHead = $("#" + checkid).children(".container-accordion").children("h4").attr("class");
			$("#" + checkid).children(".container-accordion").children("h4").removeClass(classHead).addClass('corner-all no-active');
			$("#" + checkid).children(".container-accordion").children("h4").css({"color":"white", "background":"#f1414b"});
			
		}
	});
}

