var stoptimer = false;
var _currentTab = 1;
window.setTimeout('TimerChangeBackground()', 7500);
window.addEvent('domready', function() {
	InitializeNews();
	document.onkeypress = stopRKey;
	
	//Preload images...
	var myImgEn1 = new Asset.image("/Portals/_default/Skins/Dynacom Skin v01/images/Home1_en.png");
	var myImgEn2 = new Asset.image("/Portals/_default/Skins/Dynacom Skin v01/images/Home2_en.png");
	var myImgEn3 = new Asset.image("/Portals/_default/Skins/Dynacom Skin v01/images/Home3_en.png");
	var myImgFr1 = new Asset.image("/Portals/_default/Skins/Dynacom Skin v01/images/Home1_fr.png");
	var myImgFr2 = new Asset.image("/Portals/_default/Skins/Dynacom Skin v01/images/Home2_fr.png");
	var myImgFr3 = new Asset.image("/Portals/_default/Skins/Dynacom Skin v01/images/Home3_fr.png");
	
	$('thumb1').addEvent('mouseover', function(e) {
		e.stop();
		this.morph('.thumb1MouseOver');
		if(this.style.top != '5px') {
			this.style.opacity = 1.0;
		}
	});
	
	$('thumb1').addEvent('mouseout', function(e) {
		e.stop();
		this.morph('.thumb1MouseOut');
		if(this.style.top != '5px') {
			this.style.opacity = 0.5;
		}
	});
	
	$('thumb1').addEvent('click', function(e) {				
		stoptimer = true;
	});
	
	$('thumb2').addEvent('mouseover', function(e) {
		e.stop();
		this.morph('.thumb2MouseOver');
		if(this.style.top != '5px') {
			this.style.opacity = 1.0;
		}
	});
	
	$('thumb2').addEvent('mouseout', function(e) {
		e.stop();
		this.morph('.thumb2MouseOut');
		if(this.style.top != '5px') {
			this.style.opacity = 0.5;
		}
	});
	
	$('thumb2').addEvent('click', function(e) {				
		stoptimer = true;
	});
	
	$('thumb3').addEvent('mouseover', function(e) {
		e.stop();
		this.morph('.thumb3MouseOver');
		if(this.style.top != '5px') {
			this.style.opacity = 1.0;
		}
	});
	
	$('thumb3').addEvent('mouseout', function(e) {
		e.stop();
		this.morph('.thumb3MouseOut');
		if(this.style.top != '5px') {
			this.style.opacity = 0.5;
		}
	});
	
	$('thumb3').addEvent('click', function(e) {				
		stoptimer = true;
	});
});

function stopRKey(evt) {
   var evt = (evt) ? evt : ((event) ? event : null);
   var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}

function DoLogin(){
	document.location.href = "https://www.dynacom.com:1443/authentication/loginredirect.aspx?custid=" + $("txtCustId").value + "&password=" + $("txtPwd").value;
}

function EnterOnKeyPress(e){
	var characterCode;

	if (e && e.which){ 
		e = e;
		characterCode = e.which;
	}
	else {
		e = event;
		characterCode = e.keyCode;
	}

	if (characterCode == 13){
		document.location.href = "https://www.dynacom.com:1443/authentication/loginredirect.aspx?custid=" + $("txtCustId").value + "&password=" + $("txtPwd").value;
		return false;
	}
	else {
		return true;
	}
}

function SubContent_OnMouseOver(elem){
	elem.style.backgroundColor = "#E2E2E2";
	elem.style.cursor = "pointer";
}

function SubContent_OnMouseOut(elem){
	elem.style.backgroundColor = "#E9E9E9";
}

function SubContent_OnClick(tab){
			
	if(tab == 1){
	    window.location = "/erp/Default.aspx?tabid=58";
	}
	if(tab == 2){
	    window.location = "/erp/Default.aspx?tabid=64";
	}
	if(tab == 3){
	    window.location = "/industry/Default.aspx?tabid=256";
	}
}

function Navigation_OnMouseOver(elem){
	elem.style.backgroundColor = "#F7F7F7";
}

function Navigation_OnMouseOut(elem){
	elem.style.backgroundColor = "#FFFFFF";
}

function ChangeBackground(id, lang) { 
	var myFx = new Fx.Morph('divBackgroundMain', {duration: 'normal'});
	var myTx = $('MainTextLink');
	switch(id) { 
		case '2': 
			myFx.start({'opacity': 0}).chain(
				function(){ 
					this.element.setStyle('background', "transparent url('/Portals/_default/Skins/Dynacom Skin v01/images/Home2_" + lang + ".png') no-repeat");
					myTx.href = TextsAndLinks2[0];
					myTx.title = TextsAndLinks2[1];
					this.start({'opacity': 1}); 
				}
			); 
			ChangeThumbnail('thumb1', false); 
			ChangeThumbnail('thumb2', true); 
			ChangeThumbnail('thumb3', false); 
			break; 
		case '3': 
			myFx.start({'opacity': 0}).chain(
				function(){ 
					this.element.setStyle('background', "transparent url('/Portals/_default/Skins/Dynacom Skin v01/images/Home3_" + lang + ".png') no-repeat");
					myTx.href = TextsAndLinks3[0];
					myTx.title = TextsAndLinks3[1];
					this.start({'opacity': 1}); 
				}
			); 
			ChangeThumbnail('thumb1', false); 
			ChangeThumbnail('thumb2', false); 
			ChangeThumbnail('thumb3', true); 
			break; 
		default: 
			myFx.start({'opacity': 0}).chain(
				function(){ 
					this.element.setStyle('background', "transparent url('/Portals/_default/Skins/Dynacom Skin v01/images/Home1_" + lang + ".png') no-repeat");
					myTx.href = TextsAndLinks1[0];
					myTx.title = TextsAndLinks1[1];
					this.start({'opacity': 1}); 
				}
			); 
			ChangeThumbnail('thumb1', true); 
			ChangeThumbnail('thumb2', false); 
			ChangeThumbnail('thumb3', false); 
			break; 
	} 
} 

function ChangeThumbnail(id, selected){ 
	div = document.getElementById(id); 
	if(selected == true){ 
		div.style.top = '5px'; 
		div.style.opacity = '1.0'; 
		div.style.filter = 'alpha(opacity=100)'; 
	} 
	else{ 
		div.style.top = '27px'; 
		div.style.opacity = 0.5; 
		div.style.filter = 'alpha(opacity=50)'; 
	} 
} 