function e(id){return document.getElementById(id);}
  
function onRollOver(obj_img){
	obj_img.src =obj_img.src.split("-off").join("-on");	
}

function onRollOut(obj_img){
	obj_img.src = obj_img.src.split("-on").join("-off");
}  

function onNavOver(obj) {
	obj.className="navigation-on";	
}

function onNavOut(obj) {
	obj.className="navigation-off";	
}

/*----------- PROMO POPUP -------------------*/

function launchPromoPopup(obj) {
	if (obj) {
		id = obj.id + "-popup";
		if (e(id)) {
			e(id).className="promo-popup-on";	
		}	
	}
}

function closePromoPopup(obj) {
	if (obj) {
		id = obj.id + "-popup";
		if (e(id)) {
			e(id).className="promo-popup-off";	
		}	
	}
}



function getPos(inputElement) {
    var coords =  new Object();
    coords.x = 0;
    coords.y = 0;
    try {
        targetElement = inputElement;
        if(targetElement.x && targetElement.y) {
            coords.x = targetElement.x;
            coords.y = targetElement.y;
        } else {
            if(targetElement.offsetParent) {
                coords.x += targetElement.offsetLeft;
                coords.y += targetElement.offsetTop;
                while(targetElement = targetElement.offsetParent) {
                    coords.x += targetElement.offsetLeft;
                    coords.y += targetElement.offsetTop;
                }
            } else {
            }
        }
		//alert(coords.x + ' - ' + coords.y);
        return coords;
    } catch(error) {
        //alert(error.msg);
        return coords;
    }
}



var bln_popup_is_active = false;
var str_active_product_id = "";
var str_popup_container = "";
var bln_fine_to_click = true;
var disable_next_click = false;

function productPopup(container, Productid, label) {
	this.container = container;
	this.id = Productid;
	this.popupHeight = 1;
	this.popupTotalHeight;
	this.incrementAmount = 10;
	this.containerOffset = 0;
	this.ProductGlobalHeight = 0;
	this.productPosX = getPos(e(this.id)).x;
	this.productPosY = getPos(e(this.id)).y;
	
	//alert(this.productPosX + ' - ' + this.productPosY);
	
	/*if (e("popup-close")) {
		e("popup-close").style.visibility = "hidden";
	}*/
	
	/*if (disable_next_click) {
		alert("HERE");
		return;	
	}
	else {
		disable_next_click = true;	
	}*/
	
	this.animatePopup = function() {
		//alert(this.container + ' - ' + this.popupHeight + ' - ' + this.popupTotalHeight);
		var _self = this;
		this.popupHeight += this.incrementAmount;
		this.ProductGlobalHeight -= this.incrementAmount;

		if (this.popupHeight < this.popupTotalHeight) {
			var animation_timer = setTimeout(function(){ _self.animatePopup(); },  10);
			e(this.container).style.height = this.popupHeight;
			e(this.container).style.top = this.ProductGlobalHeight;
		}
		else {
			//e("popup-close").style.visibility = "visible";
			this.popupHeight = 1;
			disable_next_click = false;
		}
	}
	
	
	this.activatePopup = function(id) {
		//alert("HERE");
		/*------------------------------*/
		/* QUICK SOLUTION TO SOLVED TO INSTANCES OF THE DHTML MENUS COMING UP*/
		
		/*if (bln_popup_is_active) {
			if (e("popupGalleryWindow")) {
				e("popupGalleryWindow").style.visibility="hidden";
			}
			
			if (e("slideGalleryFeature")) {
				e("slideGalleryFeature").style.visibility="hidden";
			}
		}*/
		
		
		/*------------------------------*/
		
		var div = e(this.container);
		
		if (div) {
			/*if (div.style.visibility == "hidden") {
				bln_popup_is_active = true;	
			}
			else {
				if (this.id == str_active_product_id) {
					bln_popup_is_active = false;
					div.style.visibility="hidden";	
				}
				else {
					bln_popup_is_active = true;	
				}
			}*/
			
			var bln_popup_is_active = true;
			
			if (bln_popup_is_active) {
				var str_data_id = this.id.split("_");
				//var str_final_id = eval(label + (parseInt(str_data_id[1]) + parseInt(1)));
				var str_final_id = label;
				
				//alert(str_final_id);
				
				//str_popup_content = 'test df dfa dfas dfasd fasdf asdf asdf asd fsd';
				div.innerHTML = e(label).innerHTML;
				
				//alert(div.id);
				
				var productPosX = getPos(e(this.id)).x;
				var productPosY = getPos(e(this.id)).y;
				
				div.style.height="auto";
				div.style.visibility="visible";

				this.ProductGlobalHeight = (getPos(e(this.id)).y - 30) - this.containerOffset;
			
				//alert(this.ProductGlobalHeight);
				div.style.left = productPosX;
				div.style.top = this.ProductGlobalHeight;
				this.popupTotalHeight = div.offsetHeight + 10;
				div.style.height = "1px";
				
				this.animatePopup();	
			}
			str_active_product_id = this.id;
			str_popup_container = this.container;
		}
	}
	var bln_fine_to_click = true;
	if (bln_fine_to_click) {
	 	this.activatePopup(this.id);
	}
}



//-------------- IMAGE FADER --------------//

function Fader(container,time,frames) {
	this.container = container;
	this.time = time;
	this.num_frames = frames;
	this.start_frame = 0;
	this.previous_frame = 1;
	
	this.animationTimeout = null;
	this.framesPerSec = 20;
	this.transparencyStep = 100 / ((this.time / 4000) * this.framesPerSec);
	this.fadeUp = false;
	this.animateForward = true;
	this.currTransparency = 100;
	
	
	this.setTransparency = function (percentage) 
	{	
		var Fader = document.getElementById(this.container + this.start_frame);
	
		if(!Fader){return false;}
		if (Fader.filters != null) {
			if (typeof Fader.filters == "[object]") { //if IE6+
				Fader.filters[0].opacity = percentage;
			} else { //else if IE5.5-
				Fader.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+percentage+")";
			}
		} else if (Fader.style.MozOpacity) {
			Fader.style.MozOpacity = percentage / 101;
		} else if (Fader.style.KhtmlOpacity) {
			Fader.style.KhtmlOpacity = percentage / 100;
		}
	}
	
	
	this.animateFader = function ()
	{	
		clearTimeout(this.animationTimeout);
		
		if (this.fadeUp == false) {
			this.currTransparency -= this.transparencyStep;			
			if (this.currTransparency <= 0) {
				this.fadeUp = true;
				this.currTransparency = 0;
			}
		} else {
			this.currTransparency += this.transparencyStep
			if (this.currTransparency >= 100) {
			  this.fadeUp = false;
				this.currTransparency = 100;
			}
		}
		this.setTransparency(this.currTransparency);
		
		if (this.currTransparency == 0) {
			this.goNextFrame();
		} 
		
		if (this.currTransparency == 100) {	
			var _self = this;
			
			if (this.num_frames > 1) {
				this.animationTimeout = setTimeout(function(){ _self.animateFader(); }, this.time);
			}
			
			return;
			
		} else {
			var _self = this;
			this.animationTimeout = setTimeout(function(){ _self.animateFader(); }, 1000 / this.framesPerSec);
		}
	}
  
	
	this.goNextFrame = function() {		
		if (document.getElementById(this.container + this.start_frame)) {
				document.getElementById(this.container + this.start_frame).className="hide";	
			}
		
		if  (this.start_frame != this.num_frames) {
			this.start_frame++;
			this.setTransparency(0);
			if (document.getElementById(this.container + this.start_frame)) {
				document.getElementById(this.container + this.start_frame).className="show";
			}
			
			this.setTransparency(0);
		}
		else {
			this.start_frame = 1;
			if (document.getElementById(this.container + this.start_frame)) {
				document.getElementById(this.container + this.start_frame).className="show";
			}
		}	
	}
	this.animateFader();
}


/*------ MAIN BUTTON ------*/

function switchBtnOn(id) {
	if (e("main_button_content" + id)) {
		//left
		if (e("main_button_left_img" + id)) {
			e("main_button_left_img" + id).src='images/btn-main-left-on.gif';
		}
		
		e("main_button_content" + id).className='main_button_on';
		//right
		if (e("main_button_right_img" + id)) {
			e("main_button_right_img" + id).src='images/btn-main-right-on.gif';	
		}		
	}
}

function switchBtnOff(id) {
	if (e("main_button_content" + id)) {
		//left
		if (e("main_button_left_img" + id)) {
			e("main_button_left_img" + id).src='images/btn-main-left.gif';
		}
		
		e("main_button_content" + id).className='main_button_off';
		//right
		if (e("main_button_right_img" + id)) {
			e("main_button_right_img" + id).src='images/btn-main-right.gif';	
		}		
	}
}




