function openExternal(URL, w, h, s, n, r) { // open link in new window (for external links)
	// It is possible to bypass w and h by passing in 'noW', 'noH'
	var attr = "";
	if(typeof w != "undefined" && w!= 'noW') {
		attr += "width=" + w;
	}
	if(typeof h != "undefined" && h != 'noH') {
		attr += ",height=" + h;
	}
	if(attr.length > 0) { // when no width or height is specified, use window core defaults, do not add any other values
		attr += (typeof s != "undefined" && s === true) ? ',scrollbars=yes' : ',scrollbars=no'; // default on sized window = no scrollbars
		attr += (typeof r != "undefined" && r === false) ? ',resizable=no' : ',resizable=yes'; // default on sized window = resizable
	}
	if(attr.charAt(0)==",") {
		attr = attr.substring(1);
	}
	if(URL.indexOf("play.php") != -1){
		assetClick(URL, false);
	}
	var winExt = (!n) ? window.open(URL,'_blank',attr) : window.open(URL,n,attr);
	if(winExt && winExt.blur) {
		winExt.focus();
	}
}

function bannerImpression(ad_name, url) {
}
function bannerClick(ad_name, url) {
	window.location.href = url;
}

$(document).ready(function(){
	//set up psuedo hover for IE
	$("#header>ul>li").hover(function(){
		$(this).addClass("hover");
	}, function(){
		$(this).removeClass("hover");
	});
	
	//add class="last" to end of each subnav list
	$("#header>ul>li>ul").each(function(){
		$(this).find("li:last").addClass("last")
	});
	
	//tab switcher
	$(".tabs").each(function(){
		$(this).find(".tab_nav li:first").addClass("active");
		$(this).find("div:first").addClass("active");
		$(this).find(".tab_nav a").click(function(){
			$(this).parent().parent().find("li.active").removeClass("active");
			$(this).parent().addClass("active");
			var listitem = $(this);
			$(this).parent().parent().parent().find("div.active").fadeOut("normal", function(){
				$(this).removeClass("active");
				$(listitem).parent().parent().parent().children("div").eq($(listitem).parent().index()).addClass("active").fadeIn();
			});
			return false;
		});
	});
	
	$("#subscribe_submit, #search_submit").corner("10px");
	$(".tabs .partner_wrap:last").addClass("last");
	
	$(".index .tabs").each(function(){
		var height = $(this).parent().prev().height() + 12;
		var siblingheight = 0;
		$(this).siblings().each(function(){
			siblingheight += $(this).height();
		});
		height = height - siblingheight;
		$(this).css("height", height + "px");
	});
	
	
	$("ul.tab_nav").each(function(){
		$(this).find("li:last a").hover(function(){
			if(!$(this).parent().hasClass("active")){
				$(this).parent().parent().addClass("hover");
			}
		}, function(){
			$(this).parent().parent().removeClass("hover");
		});
	});
	
	$("#subscribe_submit").hover(function(){
		$(this).find("input").css("color", "#FFF200")
	}, function(){
		$(this).find("input").css("color", "#000")
	});

	$(".index .grid3 img").each(function(){
		var src = $(this).attr("src");
		$(this).hover(function(){
			$(this).attr("src", "/connectionmagazine/img/arrow_yellow.png");
		}, function(){
			$(this).attr("src", src);
		});
	});
	
	//disable left arrows on load
	$("h2 .arrow_left").each(function(){ 
		$(this).addClass("inactive");
	});
	
	//scroll features
	$(".grid_wrap").each(function(){
		var count = $(this).find(".grid_slider > div").length - 1; //subtract 1 to account for clearing div
		var position = 0;
		var totalToDisplay = $(this).find(".grid_slider > div:first").attr("class").replace("grid", "");
		var increment = (totalToDisplay == "2") ? 282 : 189; //width of each grid-based div
		
		if(count <= totalToDisplay){ //no need for scrolling
			$(this).parentsUntil(".content_wrap").prev().find("a, span").remove();
		}

		$(this).parent().prev().find("a").each(function(){
			$(this).click(function(){
				if($(this).hasClass("inactive")){
					return false;
				}

				if($(this).hasClass("arrow_right")){
					$(this).parentsUntil(".content_wrap").next().find(".grid_wrap").scrollTo('+='+increment, 800);
					position += 1;
					if($(this).siblings(".arrow_left").hasClass("inactive")) //if they've gone right, reactive the left
						$(this).siblings(".arrow_left").removeClass("inactive");
					if(count - position <= totalToDisplay){ //can't go right anymore
						$(this).addClass("inactive");
					}
				}
				else if($(this).hasClass("arrow_left")){
					$(this).parentsUntil(".content_wrap").next().find(".grid_wrap").scrollTo('-='+increment, 800);
					position -= 1;
					if($(this).siblings(".arrow_right").hasClass("inactive")) //if they've gone left, reactivate the right
						$(this).siblings(".arrow_right").removeClass("inactive");
					if(position == 0){ //can't go left anymore
						$(this).addClass("inactive");
					}
				}

				return false;
			});
		});
	});
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	$("a.rac").each(function() {
				var href = $(this).attr("href");
				href += "?iframe=true";
				$(this).attr("href",href);
			}).prettyPhoto({
					default_width: 427,
					default_height: 575,
					theme: "rac",
					iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>'
			});
	
	
	$("#twitter_share a").attr("href", $("#twitter_share a").attr("href") + window.location.href); //add current URL
	$("#email_friend a").click(function(){
		openExternal("http://www.novell.com/info/sendemail.php?url="+encodeURIComponent(location.href),535,810,true,"_blank",true);
		return false;
	});
});

function trim(s) {
	return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}
function formCheck(f) {
	var allgood = true;
	var email = trim($('#email_address').val());
	if ((email.length == 0) || (email == "Enter your e-mail address")) {
		allgood = false;
		alert("You must enter an e-mail address.");
	}
	else if (!/^.+@.+$/.test(email)) {
		allgood = false;
		alert("You must enter a valid e-mail address.");
	}
	
	return allgood;
}
function ajaxSubmit(f) {
	var allgood = formCheck(f);
	if (allgood) {
		var formmethod = $('#subscribeform').attr('method');
		var formaction = $('#subscribeform').attr('action');
		var inputs = $("#subscribeform").serialize();
		//$.post(formaction, inputs, callback);
		$.ajax({
			type: formmethod,
			url: formaction,
			data: inputs,
			error: errorCallback,
			cache: false 
		});
	}
	return false;
}

/* open link in new window (mainly for links to external site)
---------------------------------------------------- */
function openExternal(URL, w, h, s, n, r) {
	// It is possible to bypass w and h by passing in 'noW', 'noH'
	var attr = "";
	if(typeof w != "undefined" && w!= 'noW') attr += "width=" + w;
	if(typeof h != "undefined" && h != 'noH') attr += ",height=" + h;
	if(attr.length > 0) { // when no width or height is specified, use window core defaults, do not add any other values
		attr += (typeof s != "undefined" && s == true) ? ',scrollbars=yes' : ',scrollbars=no'; // default on sized window = no scrollbars
		attr += (typeof r != "undefined" && r == false) ? ',resizable=no' : ',resizable=yes'; // default on sized window = resizable
	}
	if(attr.charAt(0)==",") attr = attr.substring(1);
	var winExt = (!n) ? window.open(URL,'_blank',attr) : window.open(URL,n,attr);
	if(winExt && winExt.blur) winExt.focus();
}

function showPrinterFriendly() {
	var pfwindow = window.open(location.href,"printer_friendly");
	pfwindow.focus();
}

if(window.name == "printer_friendly") {
	document.write('<link rel="stylesheet" type="text/css" href="/common/inc/css/connection_mag_print.css" title="Printer Friendly" />');
	var s_prop15=location.href;
}

