/* :::::::::::::::::::::::::::::::::::::::::::::::::: */
/* RUN WHEN DOM BECOMES AVAILABLE */
/* :::::::::::::::::::::::::::::::::::::::::::::::::: */
$(document).ready(function(){		
	//FLASH REPLACEMENT
	$('#pricing_btn').flash({
		src: "swf/pricing_btn.swf",
		width: 434,
		height: 105,
		params: {wmode: "transparent", menu: "false"},
		flashvars: {destURL: "106/product-info/scheduled-pricing.php"}
	});
	
	$('#maps_btn').flash({
		src: "swf/maps_btn.swf",
		width: 434,
		height: 105,
		params: {wmode: "transparent", menu: "false"}
	});
	
	$('#the_advantage_btn').flash({
		src: "swf/advantage_btn.swf",
		width: 434,
		height: 98,
		params: {wmode: "transparent", menu: "false"},
		flashvars: {destURL: "100/the-advantage/current-issue.php"}
	});
	
	if($.browser.safari){
		$('#employee_slideshow').flash({
			src: "swf/employee_slideshow_safari.swf",
			width: 200,
			height: 212,
			version: 8,
			params: {wmode: "transparent", menu: "false"}
		});
	} else {
		$('#employee_slideshow').flash({
			src: "swf/employee_slideshow.swf",
			width: 200,
			height: 212,
			params: {wmode: "transparent", menu: "false"}
		});
	}
	
	$('#angle_animation_1').flash({
		src: "swf/grey_slashes.swf",
		width: 225,
		height: 45,
		params: {wmode: "transparent", menu: "false"}
	});
	
	$('#angle_animation_2').flash({
		src: "swf/slashesInterior.swf",
		width: 225,
		height: 25,
		params: {wmode: "transparent", menu: "false"}
	});
	
	$('#import_export_map').flash({
		src: "swf/import_export_map.swf",
		params: {menu: "false"}
	});

	//SUCKERFISH NAV
	$("#top_nav li").hover( 
	 	function(){ $("ul", this).show(); },
		function() {$("ul", this).hide(); }
    );
    if (document.all) {
        $("#top_nav li").hoverClass("sfHover");
    }
	
	var isMac = /Mac/.test(navigator.userAgent);
	if(isMac){
			
		$("#top_nav").hover( 
			function(){ $(".employee_slideshow").css({visibility: "hidden"}); },
			function(){ $(".employee_slideshow").css({visibility: "visible"}); }
		);
	}
	
	//REPEAT TOP NAV ITEMS AS FIRST ITEM
	$("#top_nav>li").each(function(){
		if($("ul", this).length){
			var a = $("a:first", this).attr("href");
			var t = $("a:first", this).attr("title");
			
			if(t.toLowerCase() != "maps") $("ul", this).prepend('<li><a href="' + a + '">' + t + '</a></li>');
		}
	});
	
	//NEWS TICKER
	$("#headlines").newsTicker(6000);
	
	//IE6 Interior Page hdr cleanup
	$("#interior_pg_hdr h2").each(function(){
		if($(this).html() == "") $(this).remove();								   
	});
	
	//EVENT HANDLERS
	$("#home_btn").click(function(){
		window.location = "index.php";							  
	});
	
	//STRART HIDDEN
	$("#us_import_data").hide();
	
	//CLEAN UP
	$(".MsoNormal, .MsoBodyTextIndent").each(function(){
		$(this).attr("style", "").removeClass("MsoNormal");							  
	})
	
	if($("img[@src$='theadvantage.gif']").length){
		$("#middle table:eq(1)").addClass("data_tbl");
		$("#middle table:eq(2)").addClass("data_tbl");
	}
	
//	$("#insight p").hide();
});


/* :::::::::::::::::::::::::::::::::::::::::::::::::: */
/* FUNCTIONS */
/* :::::::::::::::::::::::::::::::::::::::::::::::::: */

function showMap(){
	$(".plus").hide();
	//TB_show('', 'map.php?KeepThis=true&TB_iframe=true&height=638&width=821', false);
	window.open('/map.php', 'us_map', 'resizeable=no,scrollbars=no,status=no,toolbar=no,height=665,width=866', true);
}

function showMapEurope(){
	$(".plus").hide();
	//TB_show('', 'map_europe.php?KeepThis=true&TB_iframe=true&height=638&width=821', false);
	window.open('/map_europe.php', 'us_map', 'resizeable=no,scrollbars=no,status=no,toolbar=no,height=665,width=866', true);
}

function showMapAsia(){
	$(".plus").hide();
	//TB_show('', 'map_asia.php?KeepThis=true&TB_iframe=true&height=638&width=821', false);
	window.open('/map_asia.php', 'us_map', 'resizeable=no,scrollbars=no,status=no,toolbar=no,height=665,width=866', true);
}

function showExportData(){
	$("#us_import_data").hide();
	$("#us_export_data").show("fast");
}

function showImportData(){
	$("#us_export_data").hide();
	$("#us_import_data").show("fast");
}

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};

var formatDateTime = function(formatDate, formatString) {
    if (formatDate instanceof Date) {
        var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
        var days = new Array("Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun");
        var f = new Array("st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "st");
        var yyyy = formatDate.getFullYear();
        var yy = yyyy.toString().substring(2);
        var m = formatDate.getMonth();
        var mm = m < 10 ? "0" + m : m;
        var mmm = months[m];
        var d = formatDate.getDate();
        var dd = d < 10 ? "0" + d : d;
        var ddd = days[formatDate.getDay()];

        var h = formatDate.getHours();
        var tt = h < 12 ? "AM" : "PM";
        if (h == 0) { h = 24; tt = "AM"; }
        h = h > 12 ? h - 12 : h;
        var hh = h < 10 ? "0" + h : h;
        var n = formatDate.getMinutes();
        var nn = n < 10 ? "0" + n : n;
        var s = formatDate.getSeconds();
        var ss = s < 10 ? "0" + s : s;

        //formatString = formatString.replace(/yyyy/i, yyyy);
        //formatString = formatString.replace(/yy/i, yy);
        formatString = formatString.replace(/mmm/i, mmm);
        formatString = formatString.replace(/mm/i, mm);
        formatString = formatString.replace(/m/i, m);
        formatString = formatString.replace(/ddd/i, ddd);
        formatString = formatString.replace(/dd/i, dd);
        formatString = formatString.replace(/d/i, d);        
        formatString = formatString.replace(/tt/i, tt);
        formatString = formatString.replace(/hh/i, hh);
        formatString = formatString.replace(/h/i, h);
        formatString = formatString.replace(/nn/i, nn);
        formatString = formatString.replace(/n/i, n);
        formatString = formatString.replace(/f/i, f[d-1]);
        //formatString = formatString.replace(/ss/i, ss);
        //formatString = formatString.replace(/s/i, s);

        return formatString;
    } else {
        return "";
    }
}

function tweetMe(d) {
    var tweet = d[0];
    if (!tweet) return;

    var txt = tweet.text;
    var at = tweet.created_at;
    var values = at.split(" ");
    at = values[0] + " " + values[1] + " " + values[2] + " " + values[3] + " UTC" + values[4] + " " + values[5];

    var src = tweet.source;
    
    at = formatDateTime(new Date(at), "h:nn tt mmm df") + " from " + src;

    var txt2 = txt.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
        return '<a href="' + url + '">' + url + '</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
        return reply.charAt(0) + '<a href="http://twitter.com/' + reply.substring(1) + '">' + reply.substring(1) + '</a>';
    });

    document.getElementById("tweet-txt").innerHTML = txt2 + "<div id=\"tweet-dte\">" + at + "</div>";
}