var old_area = '';

$(document).ready(function() {


			$(".middle_content a").each(function() {
				var title = $(this).attr("title");
				if(title == "embed_video")
				{
					$(this).addClass("embed_video");
				}
			});

			var playerLink = jQuery(document.createElement("a"));
			var videoLink = $(".embed_video").attr("href");
			playerLink.attr("id", "player");
			playerLink.attr("href", videoLink);
			playerLink.attr("class", "video_player");
			$(".embed_video").attr("id", "tmp_link");
			$("#tmp_link").after(playerLink);
			$("#tmp_link").remove();

			if(videoLink)
			{
				flowplayer("player", "/flowplayer/flowplayer-3.1.3.swf",  { 
					clip: { 
						autoPlay: false,  
						autoBuffering: true   
					} 
				});
			}



	var ie = false;
	
	if($.browser.msie) {

		ie = true;
//alert(ie);
		if(document.getElementById('quick_facts')) {

			var factH = document.getElementById('quick_facts').offsetHeight;
			var contH = document.getElementById('right_content').offsetHeight;
// 			if(factH > contH)
				document.getElementById('right_content').style.height = (factH)+'px';
	
//			$('#quick_facts').removeClass('floatPos');
//			$('#quick_facts').addClass('absolutePos');

		}

	}


//	$("#nav li a:last").addClass("nl");


	$('#faqs').accordion({ 
		active: false, 
		active: '.selected',
		header: '.head', 
		navigation: true, 
		event: 'click',
		autoheight: false,
		animated: 'easeslide'
	});

	$('#navigation').accordion({
		active: false, 
		active: '.selected',
		header: '.head', 
		navigation: true, 
		event: 'click', 
		autoheight: false,
		animated: 'easeslide' 
	});

	$(".sector").hover(
		function () {
			this.style.cursor = "pointer";
			this.style.cursor = "hand";
		},
		function () {

		}
	);


	$(".sector").click(
		function () {
			var id = this.id;
			id = id.replace('tab_', '');
			toggleContent(id);
			return false;
		},
		function () {

		}
	);


//	var break = '<div class="break"></div>';

//	$(break).insertAfter.$("body#body_home div.middle_content.home img");
//	$(break).insertAfter.$("body#body_solutions div.middle_content img");

	$("body#body_home div.middle_content.home img").addClass("break");
	$("body#body_solutions div.middle_content img").addClass("break");

	$("div.sector:first").addClass("active");

	var url = window.location.href.split("/");
	var sec = url[4];
	var pag = url[5];


	old_area = $("div.sector:first").attr("id");

	if(typeof(old_area)!="undefined")
	{
		old_area = old_area.replace('tab_', '');
	}

	$("div.sector").each(function() {
		var id = $(this).attr("id");

		if(id != old_area)
		{
//			$("#menu_"+id).hide();
			$("#content_"+id).hide();
			$("#h4_"+id).hide();
		}

	});


	


	if(url[3] == 'home') {
		if(sec != old_area)
			toggleContent(sec);
	}

	externalLinks();




});



		function submitForm(){

			var new_url = ''+location.href;
			new_url = new_url.replace('#viewComments', '');
			
			
			var form_url = $("#commentForm").attr("action");
			$("#commentForm").attr("action",''+new_url+'#viewComments');
			$("#commentForm").submit();

		}





function toggleContent(area) {

	if(area == old_area)
	{
		return;
	}

	$('#'+old_area).removeClass('active');
	$('#'+area).addClass('active');

	$("#menu_"+old_area).hide();
	$("#content_"+old_area).hide();
	$("#h4_"+old_area).hide();

	$("#menu_"+area).fadeIn("slow", 0);
	$("#content_"+area).fadeIn("slow", 0);
	$("#h4_"+area).fadeIn("slow", 0);

	old_area = area;

}


function externalLinks() {

  var theLinks = document.links;

	if (!document.links)
		{
		document.links = document.getElementsByTagName('a');
		}


	for (i=0; i < theLinks.length; i++) {
		var thisLink = theLinks[i];
		  if (thisLink.className.indexOf('new_window') != -1) {
    			thisLink.target = "_blank";
   			}
  	}
}


function track_downloads(div)
{


	$(div).each(function() {

		if($(this).attr("hostname") == location.host)
		{
			var isDoc = $(this).attr("href").match(/\.(?:doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)($|\&|\?)/);

			if(isDoc)
			{

				var download = $(this).attr("href");
				download = download.replace(/https?:\/\/(.*)/,"$1");
				download = '/download' + download;

				$(this).click(function () {
					pageTracker._trackPageview(download);
				});


			}

		}
	

	});

	return;

}

