vcc.sSurveyUrl = null;
vcc.sSurveyWidth = "300";
vcc.sSurveyHeight = "300";

vcc.bSurveyShouldBeLaunched = false;

vcc.setSurveyStatus = function(bStatus) {
	vcc.bSurveyShouldBeLaunched = bStatus;
}

$(window).unload(function () {
	vcc.launchSurvey();
});


vcc.launchSurvey = function() {
	//Check if cookie exists. If it does, do not show the survey
	if (vcc.getCookie("S60HubSurvey"))
		return;
	//Open popupwindow with survey here
	if (vcc.sSurveyUrl != null) {
		var newWindow = vcc.openWindow(vcc.sSurveyUrl, "survey", "width=" + vcc.sSurveyWidth + ",height=" + vcc.sSurveyHeight + ",location=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
		if (newWindow != null) {
			//Set cookie
			var objExpires = new Date();
			objExpires.setFullYear(objExpires.getFullYear() + 1);
			vcc.setCookie("S60HubSurvey", "true", objExpires, "/");
		}
	}
	
}

/* Cookie functions start */

vcc.setCookie = function(strName, strValue, objExpires, strPath) {
	var strCookie = strName + "=" + escape(strValue)
	if(objExpires) strCookie += ";expires=" + objExpires.toGMTString()
	if(strPath) strCookie += ";path=" + strPath
	document.cookie = strCookie
}

vcc.getCookie = function(strName) {
	var t=document.cookie.match(new RegExp(strName + "=([^;]*)"))
	return (t)?unescape(t[1]):t
}

vcc.delCookie = function(strName) {
	if (vcc.getCookie(strName)) document.cookie = strName + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT"
}

/* Cookie functions end */

vcc.hideOverlay = function() {
	$(window).unbind("resize", vcc.handleOverlayWhenResized);
	$("#overlay").fadeOut(500);
	if ($("#overlay-container #flashLightBoxContainer").length > 0) {
		swfobject.removeSWF("flashLightBoxContainer");
	} else if ($("#overlay-container #large").length > 0) {
		swfobject.removeSWF("large");
	}
	$("#overlay-container").replaceWith("<div id=\"overlay-container\"></div>");
	$("#overlay-container").hide();
	vcc.centerLightBoxVertically = false;
	if (vcc.bSurveyShouldBeLaunched) {
		vcc.launchSurvey();
	}
	vcc.bSurveyShouldBeLaunched = false;
}

vcc.showOverlay = function(oOnClickFunction, sOverlayHtml, iOverlayWidth, iOverlayHeight, bDisableBorders) {
	var ie6 = (jQuery.browser.msie && navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	var oOverlay = document.getElementById("overlay");
	if (oOverlay == null) {
		oOverlay = document.createElement("div");
		oOverlay.id = "overlay";		
		document.body.appendChild(oOverlay);
		if (!ie6) {
			$("#overlay").css({
				"background-image": "url(/SiteCollectionDocuments/Campaigns/MY11/S60/NaughtyVolvo/overlay_gradient.png)",
				"background-repeat": "repeat-x",
				"background-color": "transparent"			
			});
		}
		oOverlay.onclick = oOnClickFunction;
	}
		
	vcc.resizeOverlay();
	$("#overlay").fadeIn();
	
	$("#overlay").show();	
	if (sOverlayHtml == null)
		return;		
	var oOverlayContainer = document.getElementById("overlay-container");
	if (oOverlayContainer == null) {
		oOverlayContainer = document.createElement("div");
		oOverlayContainer.id = "overlay-container";
		document.body.appendChild(oOverlayContainer);
	}	
	oOverlayContainer.style.width = (iOverlayWidth) ? iOverlayWidth + "px" : "auto";
	oOverlayContainer.style.height = (iOverlayHeight) ? iOverlayHeight + "px" : "auto";	
	oOverlayContainer.innerHTML = sOverlayHtml + "<a href=\"#\" id=\"overlay-closebutton\" onclick=\"vcc.hideOverlay();return false;\"></a>";
	if (bDisableBorders) {
		$("#overlay-container").css("padding", 0);
	} else {
		$("#overlay-container").corner("3px cc:#4c4c4c sc:#fff");
		$("#overlay-container").css("padding", "8px");
	}
	$("#overlay-container").show();
	vcc.center(oOverlayContainer, true, vcc.centerLightBoxVertically);	
	$(window).bind("resize", vcc.handleOverlayWhenResized);
}
