window.onload = addFeaturesSwitchEvents;

var currentFullFeaturesListText;

function addFeaturesSwitchEvents() {
	featureSwitchActive1 = new Image(); 
	featureSwitchActive1.src = "images/features-switch-active-1.gif";
	featureSwitchActive2 = new Image(); 
	featureSwitchActive2.src = "images/features-switch-active-2.gif";
	featureSwitchActive3 = new Image(); 
	featureSwitchActive3.src = "images/features-switch-active-3.gif";
	featureSwitchActive4 = new Image(); 
	featureSwitchActive4.src = "images/features-switch-active-4.gif";
	featureSwitchHover1 = new Image(); 
	featureSwitchHover1.src = "images/features-switch-hover-1.gif";
	featureSwitchHover2 = new Image(); 
	featureSwitchHover2.src = "images/features-switch-hover-2.gif";
	featureSwitchHover3 = new Image(); 
	featureSwitchHover3.src = "images/features-switch-hover-3.gif";
	featureSwitchHover4 = new Image(); 
	featureSwitchHover4.src = "images/features-switch-hover-4.gif";

	featuresSwitchArea1 = document.getElementById("features_switch_1");
	addListener(featuresSwitchArea1, "mouseover", onMouseOverFeaturesSwitch, false);
	addListener(featuresSwitchArea1, "mouseout", onMouseOutFeaturesSwitch, false);
	
	featuresSwitchArea2 = document.getElementById("features_switch_2");
	addListener(featuresSwitchArea2, "mouseover", onMouseOverFeaturesSwitch, false);
	addListener(featuresSwitchArea2, "mouseout", onMouseOutFeaturesSwitch, false);
	
	featuresSwitchArea3 = document.getElementById("features_switch_3");
	addListener(featuresSwitchArea3, "mouseover", onMouseOverFeaturesSwitch, false);
	addListener(featuresSwitchArea3, "mouseout", onMouseOutFeaturesSwitch, false);
	
	featuresSwitchArea4 = document.getElementById("features_switch_4");
	addListener(featuresSwitchArea4, "mouseover", onMouseOverFeaturesSwitch, false);
	addListener(featuresSwitchArea4, "mouseout", onMouseOutFeaturesSwitch, false);
	
	if(document.getElementById("features_switch_main_1")) {
		addFeaturesSwitchEvents_1();
	}
	else if(document.getElementById("features_switch_main_2")) {
		addFeaturesSwitchEvents_2();
	}
	else if(document.getElementById("features_switch_main_3")) {
		addFeaturesSwitchEvents_3();
	}
	else if(document.getElementById("features_switch_main_4")) {
		addFeaturesSwitchEvents_4();
	}
	
	currentFullFeaturesListText = document.getElementById("features_ces");
	if(currentFullFeaturesListText) {
		currentFullFeaturesListText.style.display = "block";
	}
}

function onMouseOverFeaturesSwitch(e) {
	if (!e) var e = window.event
	featuresSwitchImage = document.getElementById("features_switch");
	
	eventSource = getEventTarget(e);
	eventSourceId = eventSource.getAttribute("id");
	
	if (eventSourceId == "features_switch_1") {
		featuresSwitchImageURL = "images/features-switch-hover-1.gif";
	} else if (eventSourceId == "features_switch_2") {
		featuresSwitchImageURL = "images/features-switch-hover-2.gif";
	} else if (eventSourceId == "features_switch_3") {
		featuresSwitchImageURL = "images/features-switch-hover-3.gif";
	} else if (eventSourceId == "features_switch_4") {
		featuresSwitchImageURL = "images/features-switch-hover-4.gif";
	}
	
	featuresSwitchImage.setAttribute("src", featuresSwitchImageURL);
}

function onMouseOutFeaturesSwitch(e) {
	if (!e) var e = window.event
	
	featuresSwitchImage = document.getElementById("features_switch");
	featuresSwitchImage.setAttribute("src", featuresSwitchBackgroundImage);
}

function showFeaturesText(objectId) {
	currentFullFeaturesListText.style.display = "none";
	currentFullFeaturesListText = document.getElementById(objectId);
	currentFullFeaturesListText.style.display = "block";
}

// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling) {
	bubbling = bubbling || false;
	
	if(window.addEventListener) { // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	} else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} else return false;
}

// Cross-browser implementation of e.target
function getEventTarget(e) {
	var targ;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}
