var ajaxManager;
if($.browser.msie && $.browser.version <= 6)
	ajaxManager = $.manageAjax({manageType: 'queue', maxReq: 1, blockSameRequest: true});
else
	ajaxManager = $.manageAjax({manageType: 'queue', maxReq: 0, blockSameRequest: true});
	
var prioritizedQueue = [];

function queueAdsSlideIn(adsUrl, adsDivWidth, animateDuration, minPageWidth){
	ajaxManager.add({
		type: "GET",
		url: adsUrl,
		dataType: "html",
		cache: true,
		success: function(html){
			if(html != null && html.length > 3){
				$('body').attr("class", $('body').attr("class")+" ihb-rightcolumn");
				$("#ihb-ads-container").html(html);
				var wrapperHeight = $("#ihb-wrapper").height();
				var windowGTbody = ($('#ihb-ads-container').height() > wrapperHeight);
				if (windowGTbody) {
					$("#ihb-ads-container").animate({left: "0px"}, animateDuration, function(){
						$("body").attr('class', $('body').attr("class")+" ihb-rightcolumn-grey-back");
					});
				}
				else{
					$("#ihb-ads-container").animate({left: "0px", height: wrapperHeight}, animateDuration, function(){
						$("body").attr('class', $('body').attr("class")+" ihb-rightcolumn-grey-back");
					});
				}
				$('body').css({'min-width': minPageWidth});
				if($.browser.msie && $.browser.version <= 6){
					$('#ihb-public').attr("style", 'width: expression(document.documentElement.clientWidth <= '+minPageWidth+'? "'+minPageWidth+'": "100%")');
					$('#ihb-private').attr("style", 'width: expression(document.documentElement.clientWidth <= '+minPageWidth+'? "'+minPageWidth+'": "100%")');
				}
			}
		}
	});
}
function queueAdsFixed(adsUrl){
	ajaxManager.add({
		type: "GET",
		url: adsUrl,
		dataType: "html",
		cache: true,
		success: function(html){
			if(html != null && html.length > 3){
				$("#ihb-ads").html(html);	
			}
		}
	});
}

function queueAlerts(alertsUrl){
	ajaxManager.add({
		type: "GET",
		url: alertsUrl,
		dataType: "html",
		cache: true,
		success: function(html){
			if(html.indexOf("<html") == -1){
				$("#ihb-alerts").html(html);
			}
			$("#ihb-alerts-loading").fadeOut("fast");
		    $("#ihb-alerts").fadeIn("slow");
		}
	});
}

function addFunctionToPrioritizedQueue(priority, funcString){
	prioritizedQueue[priority] = funcString;
}

function handlePrioritizedQueue(){
	$.map(prioritizedQueue, function(n){
      eval(n);
    });
}

function clickTracker(adsClickTrackUrl, adId, redirectToUrl, target){
	$.ajax({
		type: "POST",
		url: adsClickTrackUrl,
		cache: false,
		data: "adId="+adId,
		complete: function(){
			if(target != 'blank')
				window.location.href = redirectToUrl;
			else
				window.open(redirectToUrl);
		}
	});
}
