/**
	DIV Switcher Object
	Written by Daniel Fekete
	Created for VOOV Ltd. - 2008
	2008 copyright VOOV Ltd. All rights reserved!

*/

switcher = {
	switches: 8,
	switcher_div: "switcher_",
	speed: 5000,
	current_div: 0,
	prev_div: -1,
	switch_timer: null,
	onSwitch: function(idx) {},
	switchTo: function(value) {
		// Az összes divet, ami nem value, azt tüntessük el, a value-t
		// jelenítsük meg
		for(var i=0; i<this.switches; i++) {
			//var o = document.getElementById(this.switcher_div + i);
			
			if (i == value)  this.setOpacity(this.switcher_div + i, 10);
			else this.setOpacity(this.switcher_div + i, 0);
		}
		// töröljük a timer-t, hogy ne lépkedjen tovább
		if (this.switch_timer != null) clearInterval(this.switch_timer);
		this.onSwitch(value);
		this.current_div = value;
		// Az onclick miatt
		return false;
	},
	
	toNext: function() {
		var next = this.current_div + 1;
		if (next == this.switches) next = 0;
		this.switchTo(next);
		
		return false;
	},
	
	toPrev: function() {
		var prev = this.current_div - 1;
		if (prev == -1) prev = this.switches - 1;
		this.switchTo(prev);		
		
		return false;
	},
	
	m_interval: function() {

		this.initFade(this.switcher_div + this.current_div, 0, 10);
		
		// lépjünk a következőre
		this.current_div++;
		if (this.current_div == this.switches) this.current_div = 0;
		

		this.initFade(this.switcher_div + this.current_div, 10, 0);
		this.onSwitch(this.current_div);
		
	},
	
	setOpacity: function(obj_name, value) {
		if (value == 0) document.getElementById(obj_name).style.display = "none";
		else document.getElementById(obj_name).style.display = "block";
		document.getElementById(obj_name).style.opacity = value/10;
		document.getElementById(obj_name).style.filter = "alpha(opacity=" + value*10 + ")";
	},
	
	initFade: function(obj_name, target_op, current_op) {
		var counter = 0;
		while (target_op != current_op) {
			if (target_op > current_op) current_op++;
			else if (target_op < current_op) current_op--;
			var timeout_string = "switcher.setOpacity('" + obj_name + "', " + current_op + ")"; 
			setTimeout(timeout_string, 100*counter);
			counter++;	
		}
		
		
	},
	
	addEvent: function( obj, type, fn ) {
	    if ( obj.attachEvent ) {
	        obj['e'+type+fn] = fn;
	        obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
	        obj.attachEvent( 'on'+type, obj[type+fn] );
	    } else
	        obj.addEventListener( type, fn, false );
	}, 	 
	
	initalize: function(num_of_switches) {
		// Tegyük be document.onload-ba
		if (typeof(num_of_switches) != "undefined")
			switcher.switches = num_of_switches;
			 
		this.addEvent(window, "load", function() {
			// eltüntetjük az összes divet, amit szabad, de
			var o = document.getElementById(switcher.switcher_div + "0");
			o.style.display = "block"; 
			var neg_counter = 0;
			for(var i=1; i<switcher.switches; i++) {
				// Az elsőt nem tüntetjük el
				var o = document.getElementById(switcher.switcher_div + i);
				if (!o) {
					neg_counter++;
					continue;
				} 
				o.style.display = "none";
				// csináljunk timert:
			}
			switcher.switches -= neg_counter;
			switcher.switch_timer = setInterval("switcher.m_interval()", switcher.speed);
		})
	}
}

switcher.initalize(8);
switcher.onSwitch = function(idx){
	var sw_0 = document.getElementById("sw_0");                
	var sw_1 = document.getElementById("sw_1");                
	var sw_2 = document.getElementById("sw_2");                
	var sw_3 = document.getElementById("sw_3");                
	var sw_4 = document.getElementById("sw_4");                
	var sw_5 = document.getElementById("sw_5");                
	var sw_6 = document.getElementById("sw_6");                
	var sw_7 = document.getElementById("sw_7");                
	sw_0.src = "images/deals_box_1.jpg";                
	sw_1.src = "images/deals_box_1.jpg";                
	sw_2.src = "images/deals_box_1.jpg";                
	sw_3.src = "images/deals_box_1.jpg";                
	sw_4.src = "images/deals_box_1.jpg";                
	sw_5.src = "images/deals_box_1.jpg";                
	sw_6.src = "images/deals_box_1.jpg";                
	sw_7.src = "images/deals_box_1.jpg";                
	document.getElementById("sw_" + idx).src = "images/deals_box_2.jpg";
}

function switchTo(idx){
	switcher.switchTo(idx);
	return false;                
}

function checkform(){            
	for (i = 0; i < fieldstocheck.length; i++) {                
		if (eval("document.subscribeform.elements['" + fieldstocheck[i] + "'].type") == "checkbox") {                    
			if (document.subscribeform.elements[fieldstocheck[i]].checked) {
			}
			else {
				alert("Please enter your " + fieldnames[i]);
				eval("document.subscribeform.elements['" + fieldstocheck[i] + "'].focus()");
				return false;                
			}
		}
		else {
			if (eval("document.subscribeform.elements['" + fieldstocheck[i] + "'].value") == "") {
				alert("Please enter your " + fieldnames[i]);
				eval("document.subscribeform.elements['" + fieldstocheck[i] + "'].focus()");
				return false;
			}                        
		}                    
	}                
	for (i = 0; i < groupstocheck.length; i++) {
		if (!checkGroup(groupstocheck[i], groupnames[i])) {
			return false;                        
		}                    
	}
	return true;                
}

var groupstocheck = new Array();
var groupnames = new Array();            

function addGroupToCheck(value, name){            
	groupstocheck[groupstocheck.length] = value;                
	groupnames[groupnames.length] = name;                
}

function compareEmail(){
	return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
}
function checkGroup(name, value){            
	option = -1;                
	for (i = 0; i < document.subscribeform.elements[name].length; i++) {                
		if (document.subscribeform.elements[name][i].checked) {                    
			option = i;                        
		}                    
	}                
	if (option == -1) {                
		alert("Please enter your " + value);                    
		return false;                    
	}                
	return true;                
}

function openNewWindow(URLtoOpen, windowName, windowFeatures){
	newWindow = window.open(URLtoOpen, windowName, windowFeatures);
}

function setOpacityD(value){
	document.getElementById("popup_infoD").style.opacity = value / 10;
	document.getElementById("popup_infoD").style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function fadeInMyPopupD(){
	for (var i = 0; i <= 100; i++) 
		setTimeout('setOpacity(' + (i / 10) + ')', 6 * i);
}

function fadeOutMyPopupD(){
	for (var i = 0; i <= 100; i++) {
		setTimeout('setOpacity(' + (10 - i / 10) + ')', 6 * i);
	}    
	setTimeout('popupInfoCloseD()', 800);
}

function popupInfoD(){
	document.getElementById("popup_infoD").style.display = "block";
}

function popupInfoCloseD(){
	document.getElementById("popup_infoD").style.display = "none";
}

function setOpacityP(value){
	document.getElementById("popup_infoP").style.opacity = value / 10;
	document.getElementById("popup_infoP").style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function fadeInMyPopupP(){
	for (var i = 0; i <= 100; i++) 
		setTimeout('setOpacity(' + (i / 10) + ')', 6 * i);
}

function fadeOutMyPopupP(){
	for (var i = 0; i <= 100; i++) {
		setTimeout('setOpacity(' + (10 - i / 10) + ')', 6 * i);
	}
	
	setTimeout('popupInfoCloseP()', 800);
}

function popupInfoP(){
	document.getElementById("popup_infoP").style.display = "block";
}

function popupInfoCloseP(){
	document.getElementById("popup_infoP").style.display = "none";
}