// Fixes IE6/Flash 9.0.45 issues
var destinations = "";
var header       = "";
var map          = "";
var site         = "";

function errorHandler()
{
	return true;
}

window.onerror = errorHandler;

var mainCategories = ["hyperconnectivity", "40g", "telepresence", "unified_communications", "wimax"];

function destinationMapCityClicked(cityId)
{
    if(cityId)
    {
    	if(cityId.toLowerCase() == "saopaolo")
    	{
    		cityId = "saopaulo";
    	}
    
        window.location.href = "/" + blogLanguage + "/" + cityId.toLowerCase() + ".html";
    }
}

function embedCustomerVideo(divId, videoId, configId)
{
    if(divId && videoId && configId)
    {
		var customerVideoFlash = new SWFObject("/flash/customer.swf", videoId, "651", "310", "9", "#000000");
		
		customerVideoFlash.addVariable("configPath", "/" + blogLanguage + "/flash/customers/" + videoId + "/" +  configId + ".xml");
		customerVideoFlash.addParam("allowFullScreen", "true");
		customerVideoFlash.addParam("allowScriptAccess", "always");
		customerVideoFlash.write(divId);
    }
}

function embedProductVideo(divId, videoId, configId)
{
    if(divId && videoId && configId)
    {
		var productVideoFlash = new SWFObject("/flash/product.swf", videoId, "886", "348", "9", "#3b4145");
		
		productVideoFlash.addVariable("configPath", "/" + blogLanguage + "/flash/products/" + videoId + "/" +  configId + ".xml");
		productVideoFlash.addParam("allowFullScreen", "true");
		productVideoFlash.addParam("allowScriptAccess", "always");
		productVideoFlash.write(divId);
    }
}
	
function getFlash(name) 
{
	if(navigator.appName.indexOf("Microsoft") != -1) 
	{
		return window[name];
	}
	else 
	{
		return document[name];
	}
}

function openTopicLink(topicId)
{
	switch(topicId) 
	{		
		case "advantages":
			window.location.href = "/en/feature-article.html";
			break;

		case "fortyG":
			window.location.href = "/en/40g/index.html";
			break;
		
		case "home":
			window.location.href = "/" + blogLanguage + "/";
			break;

		case "tele":
			window.location.href = "/en/telepresence/index.html";
			break;
		
		case "unified":
			window.location.href = "/en/unified_communications/index.html";
			break;
		
		case "video":
			window.location.href = "/en/what-is-hyperconnectivity.html";
			break;
		
		case "white":
			window.location.href = "/en/whitepaper-overview.html";
			break;

		case "wimax":
			window.location.href = "/en/wimax/index.html";
			break;		
	}
}
	
$(function() 
{ 
	if($("span.category-list").length > 1) 
	{
		$("#alpha").prepend('<a href="http://www.hyperconnectivity.com/en/atom.xml" target="_blank"><img src="/en/images/rss_Btn.gif" class="imgover" id="rss" border="0" style="float: right" /></a>');
	}

    $.each($("span.category-list"), function() 
    {
    	var category = $(this).attr("id").substring(1, $(this).attr("id").indexOf("~")).replace(/ /gi, "_").toLowerCase();
    
    	if($.inArray(category, mainCategories) != -1)
    	{
			$(this).before('<img src="/' + blogLanguage + '/images/category/' + category + '.gif" alt="">');
			
			if($("div.entry-content").length == 1)
			{
		        $("#beta").append('<iframe src="/' + blogLanguage + '/iframes/' + category + '.html" width="190" height="900" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>');
			}
    	}
    	else if($("div.entry-content").length == 1)
		{
			$("#beta").append('<iframe src="/' + blogLanguage + '/iframes/tag.html" width="190" height="700" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>');
		}
    });

    $.each($("span.category-archive"), function() 
    {
    	var category = $.trim($(this).attr("id")).replace(/ /gi, "_").toLowerCase();
    
    	if($.inArray(category, mainCategories) != -1)
    	{
    		$(this).css({ clear: "both", display: "block" });
	        $(this).before('<img src="/' + blogLanguage + '/images/category/' + category + '_large.gif" alt="" style="float: left;"><a href="http://feeds.feedburner.com/hyperconnectivity/' + category + '" target="_blank"><img src="/en/images/rss_Btn.gif" class="imgover" id="rss" border="0" style="float: right" /></a>');
	        $("#beta").append('<iframe src="/' + blogLanguage + '/iframes/' + category + '.html" width="190" height="900" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>');
	    }
    	else
    	{
	        $(this).before('<img src="/' + blogLanguage + '/images/mainheader-tag.gif" alt="" class="tag-image"><span class="tag-header">' + $.trim($(this).attr("id")) + '</span>');
	        $("#beta").append('<iframe src="/' + blogLanguage + '/iframes/tag.html" width="190" height="700" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>');

			$.each($("span.category-archive-list"), function() 
			{
				var category = $(this).attr("id").substring(1, $(this).attr("id").indexOf("~")).replace(/ /gi, "_").toLowerCase();
			
				if($.inArray(category, mainCategories) != -1)
				{
					$(this).before('<img src="/' + blogLanguage + '/images/category/' + category + '.gif" alt="">');
				}
			});
    	}
    });
	
    $.each($("div.entry-body img"), function() 
    {
    	$(this).removeAttr("style").addClass("blog-photo");
    });

    $("#destinationSelect").change(function() 
    {
        destinationMapCityClicked($(this).val());
    });

	if($("#carousel").length > 0)
	{
		$("#carousel").jCarouselLite(
		{
			btnNext: ".next",
			btnPrev: ".previous",
			circular: false,
			visible: 4
		});
	}

	$("#carousel li").click(function(event)
	{
		var position = $(this).prevAll().length + 1;
		
		getFlash($(this).parent().attr("class")).playVideo(position);
		
		event.preventDefault();
	});
	
    $("img.imgover, input.imgover").hover(function() 
    {
    	$(this).attr("src", $(this).attr("src").replace(/.gif/gi, "_over.gif").replace(/.jpg/gi, "_over.jpg"));
    }, 
    function() 
    {
    	$(this).attr("src", $(this).attr("src").replace(/_over.gif/gi, ".gif").replace(/_over.jpg/gi, ".jpg"));
    });
});