function setStyleClass(id, styleClass) {
    var obj = document.getElementById(id);
    if (!obj) {
        obj = getElementByName(id);
    }
    if (obj) {
        obj.className = styleClass;
    }
}

function favoris() {
	if ( navigator.appName != 'Microsoft Internet Explorer' ) { 
		window.sidebar.addPanel("Topreductions, le partenaire de vos achats","http://www.topreductions.fr",""); 
	}
	else { 
		window.external.AddFavorite("http://www.topreductions.fr","Topreductions, le partenaire de vos achats"); 
	}
}

function closePopup() {
	document.getElementById("newsPopup").style.display="none";
	setStyleClass("frame","frame");
}
function GetTopPosition(elem) {		
	var returnValue = elem.offsetTop;
	while((elem = elem.offsetParent) != null) {
		if (elem.tagName != 'HTML') returnValue += elem.offsetTop;
	}
	return returnValue;
}

function GetLeftPosition(elem) {
	var returnValue = elem.offsetLeft;
	while((elem = elem.offsetParent) != null) {
		if (elem.tagName != 'HTML') returnValue += elem.offsetLeft;
	}
	return returnValue;
}

var SlideShow = new Class({

Initialize:function() {
    this.slideCounter=1;
    this.scroll = new Fx.Scroll('top_shop', {
        wait: true,
        duration: 2000,
       // offset: { 'x':0,'y': 0},
        wheelStops: true,
        transition: Fx.Transitions.Cubic.easeInOut
        });
    this.handleTimer=this.Execute.periodical(5000,this);
},

Execute : function() {
	var counter = Math.ceil(this.slideCounter/2);
    var sScrollTo = "top_shop_"+counter;
    
    if($(sScrollTo))
		this.scroll.toElement($(sScrollTo));
    
    this.slideCounter++;
    if(this.slideCounter>20)
        this.slideCounter=1;
}
});

var SlideShowCode = new Class({

	Initialize:function() {
	    this.CounterCode=1;
	    this.scroll = new Fx.Scroll('top_code', {
	        wait: true,
	        duration: 1500,
	       // offset: { 'x':0,'y': 0},
	        wheelStops: true,
	        transition: Fx.Transitions.linear.easeIn
	        });
	    this.handleTimer=this.Execute.periodical(1500,this);
	},

	Execute : function() {
		var counter = this.CounterCode;
	    var sScrollTo = "top_code_"+counter;
	    
	    if($(sScrollTo))
			this.scroll.toElement($(sScrollTo));
	    
	    this.CounterCode++;
	    if(this.CounterCode>10)
	        this.CounterCode=1;
	}
});

var News = new Class({
	
	Record : function(value) {
		if (value=='popup') {
			var emailValue = $('email_newsletter_popup').value;

			if ( emailValue.length > 0 ) {
			
				var myAjax = new Request({
			          url:"/recordEmail.php?email="+emailValue,
			          method: 'get',
			          encoding:'ISO-8859-1',
			          onComplete: function(responseText) { // no default update element, we do it manually
			 			
			          $('newsConfirmation_popup').className='searchVisible';
			          $('newsConfirmation_popup').set('html', responseText); 
			          }
			      });
		 
		 
				myAjax.send();	
			}
		}
		else {
			var emailValue = $('email_newsletter').value;

			if ( emailValue.length > 0 ) {
			
				var myAjax = new Request({
			          url:"/recordEmail.php?email="+emailValue,
			          method: 'get',
			          encoding:'ISO-8859-1',
			          onComplete: function(responseText) { // no default update element, we do it manually
			 			
			          $('newsConfirmation').className='searchVisible';
			          //$('newsConfirmation').innerHTML=responseText;
			          $('newsConfirmation').set('html', responseText); 
			          }
			      });
		 
		 
				myAjax.send();	
			}

		}
}
	
});
