function trackAsyncPageView(name) {
	if (typeof window['GA_ACCOUNT'] !== 'undefined'){
		_gaq.push(function() {
			var pageTracker = _gat._getTracker(window['GA_ACCOUNT']); 
			pageTracker._trackPageview(name);
		});	
    }
};

function popWinDynamic(content, name, width, height, colour) 
{	
	CMSTools.popupWinCreate(content, colour, {width: width, height: height});
    
    trackAsyncPageView(name);
};

function popModalDynamic(content, name)
{
	//CMSTools.popupModal(this.href, 640, 400);
	CMSTools.popupCreate(content, "#000", 0);
	CMSTools.popupUpdateContents(content);
	//CMSTools.popupAddCloseBut();
	
	trackAsyncPageView(name);
}

function popModalURL(url, name)
{
    CMSTools.popupModal(url, 640, 400);
    trackAsyncPageView(name);
}

function popWinURL(url, name, width, height) 
{
    var popup = window.open(url, "dynamic_win", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='auto',resizable='true'");
    if (width != "" && height != ""){
        popup.resizeTo(width, height); 
    }
    popup.focus();
    trackAsyncPageView(name);
}

function openURL(url)
{
	window.open(url, "", "");
	 
	trackAsyncPageView('/outgoing/' + url);
}

function popupController (opt){
	if (opt.settings == undefined){
		opt.settings = {};
	}
	var d = popupOverlay(decodeURIComponent(opt.content), opt.label, opt.width, opt.height, opt.colour, opt.position, opt.settings);
	//return d;
}

// The overlay
function popupOverlay(content, title, width, height, colour, position, settings) {
	// remove the dialog if present
	$('#dialog').remove();
	// create new dialog
    $('body').append('<div id="dialog"></div>');
    var d = $('#dialog');
    d.css('background-color', colour)
    var html = '<span style="display:block">' + content + '</span><br />';
    d.html(html);
    d.dialog({
        autoOpen: false,
        resizable: (settings == undefined || settings.resizable == undefined ? true : settings.resizable),
        height: height,
        width: width,
        title: title,
        position: position,
        close: function() {
        	$(this).remove();
        }
    });
    if ($('#is').length == 0) {
        d.dialog('open');
        d.append('<div id="is"></div>');
    }

    // Call minicart on popup for paypal
    if (content.search("paypal") != "-1"){
	    if (MiniCart.obj == undefined){
	    	payPalMiniCart.init();
	    } else {
	    	payPalMiniCart.hijackForms();
	    }
    }
    //return d.attr('id');
}



