$(document).ready(function() {
	
/* ------------------------------------------------------------
   Select country redirect
   ------------------------------------------------------------*/
	
	$("div#selcountry h2").click(function(){
		$("div#selcountry ul").slideToggle("fast");
		return false;
	});
	$("body").click(function(){
		$("div#selcountry ul").slideUp("fast");
	});
	
/* ------------------------------------------------------------
   Add style to Select Country <h2>
   ------------------------------------------------------------*/
	$("div#selcountry").addClass("working");
	
/* ------------------------------------------------------------
   Remove left margin, padding and border on navigation lists
   ------------------------------------------------------------*/
	$("div#topnav li:first-child, ul#sitelinks li:first-child, div#footer li:first-child").addClass("navfirst");
	
/* ------------------------------------------------------------
   Remove top margin from first headings
   ------------------------------------------------------------*/
	$("div#leftnav h3:nth-child(2), div#rightcol h2:first-child").addClass("firstheading");
	
/* ------------------------------------------------------------
   Add border to Right Column if class="border"
   ------------------------------------------------------------*/
	$("div.border").wrapInner("<div><div><div><div><div><div><div><div><div></div></div></div></div></div></div></div></div></div>");
	$("div.border").css("border","none");
	$("div.border").css("padding","0");
	$("div.border").css("background","none");

/* ------------------------------------------------------------
   Add border to blockquote
   ------------------------------------------------------------*/
	$("blockquote").wrapInner("<div><div><div><div><div><div><div><div><div></div></div></div></div></div></div></div></div></div>");
	$("blockquote").css("border","none");
	$("blockquote").css("padding","0");
	$("blockquote").css("background","none");

/* ------------------------------------------------------------
   Add rounded corners to .borderblue
   ------------------------------------------------------------*/
	$("div.borderblue").wrapInner("<div><div><div><div></div></div></div></div>");
	$("div.borderblue").css("background","none");
	$("div.borderblue").css("padding","0");
	
/* ------------------------------------------------------------
   Add clear to product page list items and add right border
   ------------------------------------------------------------*/
	$("ul.product li:nth-child(odd)").css("clear","both");
	$("ul.product li:nth-child(odd)").css("margin-right","1%");
	
/* ------------------------------------------------------------
   Random Logos
   ------------------------------------------------------------*/
	$.fn.reorder = function() {
		// random array sort from
		// http://javascript.about.com/library/blsort2.htm
		function randOrd() { return(Math.round(Math.random())-0.5); }
		return($(this).each(function() {
			var $this = $(this);
			var $children = $this.children();
			var childCount = $children.length;
			if (childCount > 1) {
				$children.remove();
				var indices = new Array();
				for (i=0;i<childCount;i++) { indices[indices.length] = i; }
				indices = indices.sort(randOrd);
				$.each(indices,function(j,k) { $this.append($children.eq(k)); });
			}
		}));
	}
	if(typeof theLogos!="undefined"){
		$("#logos").html(theLogos);
		$("#logos li").hide();
	}
	function randomLogos(numLogos) {
		var i=1;
		$("#logos ul").reorder();
		for (i=1;i<=numLogos;i++) {
			$("#logos li:nth-child(" + i + ")").fadeIn();
		}
		setInterval(function() {
			$("#logos li").hide();
			$("#logos ul").reorder();
			for (i=1;i<=numLogos;i++) {
				$("#logos li:nth-child(" + i + ")").fadeIn();
			}
		}, 4000);
	}
	if(typeof logos!="undefined"){
		randomLogos(logos)
	}
});

/* ------------------------------------------------------------
   Help Window
   ------------------------------------------------------------*/
function helpWindow(src) {
    var win = window.open('/pan/helpTextServlet?helpText=' + src,'wnd','toolbar=no,location=no,menu=no,scrollbars=yes,directories=no,resizable=yes,width=300,height=300,screenX=0,screenY=0,top=0,left=0');
    win.focus();
}// from element.js


/* ------------------------------------------------------------
   Popup for privacy page
   ------------------------------------------------------------*/
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=600,height=300,scrollbars=no');
return false;
}

// 650<!-- Employees -->
// 18<!-- Offices -->
// 17<!-- European Offices -->
// 19<!-- Markets -->
// 1 700<!-- Advertisers -->
// 120 000<!-- Publishers -->
// 12<!-- Impressions -->
// 134<!-- Visitors -->
// 7.6<!-- Leads -->