dojo.require("dojox.image._base");
dojo.require("dojo._base.html");
dojo.require("dojo.fx");
dojo.require("dojo.fx.easing");

//listataan hoverkuvat
var images = new Array(
"/images/mainsquare1_hover.jpg",
"/images/mainsquare2_hover.jpg",
"/images/mainsquare3_hover.jpg",
"/images/mainsquare4_hover.jpg",
"/images/tabmenu_home_hover_red.png",
"/images/tabmenu_home_hover_blue.png",

"/images/sovellukset_btn_cms_hover.png",
"/images/sovellukset_btn_amandavip_hover.png",
"/images/sovellukset_btn_tiedostopankki_hover.png",
"/images/sovellukset_btn_virustorjunta_hover.png",
"/images/sovellukset_btn_varmuuskopiointi_hover.png",
"/images/sovellukset_btn_spam_hover.png",
"/images/yhteydet_btn_yritysinternet_hover.png",
"/images/yhteydet_btn_yritysverkko_hover.png",
"/images/yhteydet_btn_palomuurit_hover.png",
"/images/yhteydet_btn_laitesali_hover.png",
"/images/yhteydet_btn_virtuaalipalvelimet_hover.png",
"/images/yhteydet_btn_itpalvelupaketti_hover.png",
"/images/yhteydet_btn_atk_hover.png",
"/images/btn_tarjous_pun_hover.png",
"/images/btn_tarjous_sin_hover.png",
"/images/btn_tarjous_har_hover.png",
"/images/btn_tarjous_vih_hover.png"
);

dojo.addOnLoad(function(){
	//ladataan hoverkuvat
	dojox.image.preload(images);	
	
	//tables even rows
	
	if (window.location.pathname.indexOf("webhotellit") > -1 && window.location.pathname.indexOf("tilaus") == -1) {
		dojo.query("#webhotellit #wh_main tr:nth-child(even)").addClass("wh_even");
		var whrows = dojo.query("#webhotellit #wh_main tr");
		var lastrownum = whrows.length -1;
		var secondlastrownum = whrows.length -2;
		console.log(whrows[secondlastrownum]);
		dojo.removeClass(whrows[secondlastrownum],"wh_even");
		
		var yhTrs = dojo.query("#webhotellit #wh_lisa tr > td");
		yhTrs.addClass("wh_even").style("margin","0 0 2px 0");

	}
	if (window.location.pathname.indexOf("yhteydet/itpalvelupaketti") > -1 || window.location.pathname.indexOf("yhteydet/virtuaalipalvelimet") > -1) {
		dojo.query("#yhteydet table tr:nth-child(even)").addClass("wh_even");
	}
	if (window.location.pathname.indexOf("whois") > -1) {
		dojo.query("br").orphan();
    dojo.removeClass(dojo.query("#submit")[0],"fsubmit");
    dojo.query(".fsubmit").orphan();
	}
	
	
	////////////////////////////////
	// ANIMATED BANNER with block //
	////////////////////////////////
	/*	
		var slideHeight = 291;
		var slideNum = 1;
		var arraylength = dojo.query(".animimg").length;
		//console.log(slideNum);
		function slideImg2() {
			var topPos = -slideHeight * slideNum;
			//console.log("slideImg started");
			dojo.fx.slideTo({
				node: dojo.byId("animblock"),
				properties: { left: '0', top: '0', unit: 'px' },
				easing: dojo.fx.easing.expoIn,
				duration: 300,
				delay: 5000,
				onEnd: function() {
					dojo.query("#animimgs").style("top",topPos+"px");
					slideNum++;
					dojo.fx.slideTo({
						node: dojo.byId("animblock"),
						properties: { left: '-967', top: '0', unit: 'px' },
						easing: dojo.fx.easing.expoOut,
						duration: 300,
						delay: 0,
						onEnd: function() {
							slideImg2();
						}
					}).play();
					//console.log(slideNum);
					if(slideNum == arraylength) {
					//resetoidaan
					dojo.query("#banneranim").style("top","0px");
					slideNum = 0;
					}
				}
			}).play();
		}
		//set dummys content
		slideImg2();
	*/

		/////////////////////
		// ANIMATED BANNER //
		/////////////////////
	if (window.location.pathname == "/fi/" || window.location.pathname == "/fi/etusivu") {
		var slideWidth = 967;
		var slideNum = 2;
		var arraylength = dojo.query(".animimg").length;
		var lastNodeIndex = arraylength -1;
		//var maxw = arraylength * slideWidth;
		//console.log(maxw);
		//dojo.query("#animimgs").style("width",maxw);
		//console.log(slideNum);
		function slideImg3() {
			var leftPos = -slideWidth * slideNum;
			//console.log("slideImg started");
			dojo.fx.slideTo({
				node: dojo.byId("animimgs"),
				properties: { left: leftPos, top: '0', unit: 'px' },
				easing: dojo.fx.easing.expoInOut,
				duration: 1000,
				delay: 5000,
				onEnd: function() {
					slideNum++;
					//console.log(slideNum);
					if(slideNum == arraylength) {
					//resetoidaan
					dojo.query("#animimgs").style("left","0px");
					slideNum = 1;
					}
					slideImg3();
				}
			}).play();
		}
		//set dummys content
		var dummyreplacer = dojo.query(".animimg")
		dojo.byId("dummy").innerHTML = dummyreplacer[lastNodeIndex].innerHTML;
		slideImg3();
	}
	
	/////////////////////////////
	//odottakaahetki////////////

	
	dojo.query("#main_domainhaku_btn").onclick( function() {
		
		dojo.query("#odottakaahetki").style(
		{
		visibility: "visible"
		}
		);
		dojo.animateProperty({
			node: dojo.byId("odottakaahetki"),
			duration: 500,
			properties: { opacity: {start: '0', end: '1'}}
		}).play();
	});

});
