﻿





	addNamespace("atlas.DynaMarquee");

	atlas.DynaMarquee = Class.create();
	
	Object.extend(atlas.DynaMarquee.prototype, {
		objXML: null,
		state: null,
		urun: null,
		count: 0,
		display:5,
		step: 5,
		pos: 0,
		divpos: 0,
		timer: null,
		hoverdiv: null,
		slideTimer: null,
		slideDirection: 1,
		isRunning: false,
		timerInterval: 10000,
		r: null,
		w: 0,
		ondivmouseover: function(e) {
			this.div.style.display='inline';
		},
		ondivmouseout: function(e) {
			this.div.style.display='none';
		},
		onmouseover: function(e) {
			if(this.timer != null) clearTimeout(this.timer); this.timer = null;
		},
		onmouseout: function(e) {
			if(this.timer != null) clearInterval(this.timer);
			this.timer = setInterval(this.onnext.bind(this), this.timerInterval);
		},
		onnext: function(e) {
			if (this.isRunning) { return; }
			this.isRunning = true;
			this.slideDirection = 1;
			var html = "<TABLE align=\"center\" width=\"100%\" border=\"0\" cellspacing=\"6\">" +
			"<TR align=\"center\">";
			var temppos = this.pos;
			if (temppos >= this.count-1) { temppos = 0; }
			for (i = 0; i < this.display; i++) {
				var fiyatcode = "";
				switch (para) {
					case 2:  fiyatcode = this.urun[temppos].atlasfiyat1 + " " + paratipi; break;
					case 5:  fiyatcode = this.urun[temppos].atlasfiyat2 + " " + paratipi; break;
					case 6:  fiyatcode = this.urun[temppos].atlasfiyat3 + " " + paratipi; break;
					case 7:  fiyatcode = this.urun[temppos].atlasfiyat4 + " " + paratipi; break;
				}
				html += "<TD valign=\"top\">" +
							"<TABLE background=\"bg58555.gif\" height=\"180px\" width=\"100%\">" +
								"<TR>" +
									"<TD width=\"94px\" align=\"center\" valign=\"top\" height=\"180px\">" +
									"<a target=\"_top\" href=\"/default.asp?wx=xp50&id=" + this.urun[temppos].haberid + "\"><img id=\"" + this.ele.id + "_ih_" + this.timer + "_" + this.urun[temppos].haberid + "\" border=\"0\" src=\"resimler/k1_" + this.urun[temppos].id + "\" width=\"90px\"><BR>" +
									"<span class=\"kalin856444\">" + this.urun[temppos].code20 + "</span></a><BR>" + this.urun[temppos].code10 + "<BR>" + 
									"<span class=\"kalin856444renk\">" + fiyatcode + this.urun[temppos].fiy + "</span>" +
									"</TD>" +
								"</TR>" +
							"</TABLE>" +
						"</TD>";
				activateHoverMenu(this.ele.id + "_ih_" + this.timer + "_" + this.urun[temppos].id, this.urun[temppos].id, this.div.id);
				if (temppos == this.count-1) { temppos = 0; }
				else { temppos++; }
			}
	
			for(i=0; i<5; i++) {
				if (this.pos + 1 > this.count-1) { this.pos = 0;}
				else { this.pos++; }
			}
	
			html += "</TR></TABLE>";
			
			document.getElementById(this.state).innerHTML = html;
			 
			this.showSlide();
		},
		onprev: function(e) {
			if (this.isRunning) { return; }
			this.isRunning = true;
			this.slideDirection = 0;
			var html = "<TABLE align=\"center\" width=\"100%\" border=\"0\" cellspacing=\"6\">" +
			"<TR align=\"center\">";
			var temppos = this.pos;
			for(i=0; i<10; i++) {
				if (temppos - 1 < 0) { temppos = this.count-1;}
				else { temppos--; }
			}
			var temppos1 = temppos;

			for (i = 0; i < this.display; i++) {
				var fiyatcode = "";
				switch (para) {
					case 2:  fiyatcode = this.urun[temppos].atlasfiyat1 + " " + paratipi; break;
					case 5:  fiyatcode = this.urun[temppos].atlasfiyat2 + " " + paratipi; break;
					case 6:  fiyatcode = this.urun[temppos].atlasfiyat3 + " " + paratipi; break;
					case 7:  fiyatcode = this.urun[temppos].atlasfiyat4 + " " + paratipi; break;
				}
				html += "<TD valign=\"top\">" +
							"<TABLE background=\"bg58555.gif\" height=\"180px\" width=\"100%\">" +
								"<TR>" +
									"<TD width=\"94px\" align=\"center\" valign=\"top\" height=\"180px\">" +
									
									"<a target=\"_top\" href=\"/default.asp?wx=xp50&id=" + this.urun[temppos].haberid + "\"><img id=\"" + this.ele.id + "_ih_" + this.timer + "_" + this.urun[temppos].haberid + "\" border=\"0\" src=\"resimler/k1_" + this.urun[temppos].id + "\" width=\"90px\"><BR>" +
									"<span class=\"kalin856444\">" + this.urun[temppos].code20 + "</span></a><BR>" + this.urun[temppos].code10 + "<BR>" + 
									"<span class=\"kalin856444renk\">" + fiyatcode + this.urun[temppos].fiy + "</span>" +

									"</TD>" +
								"</TR>" +
							"</TABLE>" +
						"</TD>";
				activateHoverMenu(this.ele.id + "_ih_" + this.timer + "_" + this.urun[temppos].id, this.urun[temppos].id, this.div.id);
				if (temppos == this.count-1) { temppos = 0; }
				else { temppos++; }
			}
			this.pos = temppos1;
			for(i=0; i<5; i++) {
				if (this.pos + 1 > this.count-1) { this.pos = 0;}
				else { this.pos++; }
			}
	
			html += "</TR></TABLE>";
			
			document.getElementById(this.state).innerHTML = html;
			 
			this.showSlide();
		},
		showSlide: function() {
			var curObj = document.getElementById(this.state); 
			var nextObj = document.getElementById((this.state == this.ele.id + "_div1")? this.ele.id + "_div2" : this.ele.id + "_div1"); 
			if (this.slideDirection == 1) { this.curpos = this.w; }
			else { this.curpos = -1 * this.w; }
			curObj.style.left = this.curpos + "px";
			curObj.style.yIndex++;
			curObj.style.display = nextObj.style.display = "inline";

			if (curObj.filters) {
				curObj.filters.alpha.opacity = nextObj.filters.alpha.opacity = 40;
			}
			else if (document.getElementById(this.state).style.MozOpacity) {			
				curObj.style.MozOpacity = nextObj.style.MozOpacity =0.4;
			}
			this.timerSlide = setInterval(this.moveSlide.bind(this), 50);
		},
		moveSlide: function() {
			var curObj = document.getElementById(this.state); 
			var nextObj = document.getElementById((this.state == this.ele.id + "_div1")? this.ele.id + "_div2" : this.ele.id + "_div1"); 

			if (this.curpos > 0 && this.slideDirection == 1)
			{
				this.curpos = Math.max(this.curpos-25,0);
				curObj.style.left = this.curpos + "px";
			}
			else if (this.curpos < 0 && this.slideDirection == 0)
			{
				this.curpos = Math.min(this.curpos+25,0);
				curObj.style.left = this.curpos + "px";
			}
			else
			{
				clearInterval(this.timerSlide);
				if (curObj.filters) {
					curObj.filters.alpha.opacity = 100;
				}
				else if (curObj.style.MozOpacity) {
					curObj.style.MozOpacity = 1;
				}
				this.state = (this.state == this.ele.id + "_div1")? this.ele.id + "_div2" : this.ele.id + "_div1";
				nextObj.style.display = "none";
				this.isRunning = false;
			}
		},
		ondata: function() {
			if(this.objXML.readyState == 4)
			{
				if(this.objXML.status != 200) { return; }
			}
			else 
			{
				return;
			}
	
			a = new Array();
					
			var response = this.objXML.responseXML.documentElement;
			var bs = response.getElementsByTagName("sistem");
			
			for (i = 0; i < bs.length ; i++) {
				if (bs[i] == null) { continue; }

				var b = bs[i];
				var nf = null;
				var field = null;
				var code50;
				var code30id;
                                var code30fiy = "";
                                var code30haberid = "";
				var code30code20 = "";
				var code30code10 = "";
				var fiyatcode = 0;
				var atlasfiyat1 = 0;
				var atlasfiyat2 = 0;
				var atlasfiyat3 = 0;
				var atlasfiyat4 = 0;
                                
	
				field = b.getElementsByTagName("numara");
				code50 = field[0].firstChild.data;
				field = b.getElementsByTagName("resim");
				code30id = field[0].firstChild.data;


	
				if (b.getElementsByTagName("id") != null)
				{
					field=b.getElementsByTagName("id");
					if (field[0].firstChild != null) { code30haberid = field[0].firstChild.data; }
				}

                                if (b.getElementsByTagName("fiy") != null)
				{
					field=b.getElementsByTagName("fiy");
					if (field[0].firstChild != null) { code30fiy = field[0].firstChild.data; }
				}


                                if (b.getElementsByTagName("urun") != null)
				{
					field=b.getElementsByTagName("urun");
					if (field[0].firstChild != null) { code30code20 = field[0].firstChild.data; }
				}
				


				if (b.getElementsByTagName("uretici") != null)
				{
					field=b.getElementsByTagName("uretici");
					if (field[0].firstChild != null) 
					{ 
						code30code10 = field[0].firstChild.data;
						if (code30code10 .substring(code30code10 .length-1) == ",")
						{
							code30code10 = code30code10 .substring(0,code30code10 .length-1);
						}
					}
				}

				field=b.getElementsByTagName("fiyat1");
				nf = new NumberFormat(field[0].firstChild.data);
				nf.setPlaces(2);
				nf.setSeparators(true);
				atlasfiyat1 = nf.toFormatted();

				field=b.getElementsByTagName("fiyat2");
				nf = new NumberFormat(field[0].firstChild.data);
				nf.setPlaces(2);
				nf.setSeparators(true);
				atlasfiyat2 = nf.toFormatted();
				
				field=b.getElementsByTagName("fiyat3");
				nf = new NumberFormat(field[0].firstChild.data);
				nf.setPlaces(2);
				nf.setSeparators(true);
				atlasfiyat3 = nf.toFormatted();

				field=b.getElementsByTagName("fiyat");
				nf = new NumberFormat(field[0].firstChild.data);
				nf.setPlaces(2);
				nf.setSeparators(true);
				atlasfiyat4 = nf.toFormatted();

				var code30 = new atlas.code30(i, code30id, code30fiy, code30haberid, code30code20, code30code10, "", fiyatcode, atlasfiyat1, atlasfiyat2, atlasfiyat3, atlasfiyat4);
				a[i] = code30;
				this.count = i + 1;
				
			}
			this.urun = a;
			if(this.timer != null) clearInterval(this.timer);
			this.onnext();
			this.timer = setInterval(this.onnext.bind(this), this.timerInterval);
		},
		initialize: function(objId, url, preBtnId, nextBtnId, interval, stepcount, w, h) {
			this.step = stepcount;
			this.timerInterval = interval;
			this.ele = $(objId);
			var r = MS.Position.getBounds(this.ele);
			this.ele.innerHTML = "";
			var btnPrev = document.getElementById(preBtnId);
			var btnNext = document.getElementById(nextBtnId);

			btnPrev.style.cursor = "pointer";
			btnNext.style.cursor = "pointer";


			this.curpos = w;
			this.w = w;
			
			this.ele.innerHTML = '<div style="position:relative;width:'+w+'px;height:'+h+'px;overflow:hidden"><div id="'+objId+'_div1" style="position:absolute;background-color:#D8EBFB;width:'+w+'px;height:'+h+'px;left:'+w+'px;filter:alpha(opacity=40);-moz-opacity:0.4;"></div><div id="'+objId+'_div2" style="position:absolute;background-color:#D8EBFB;width:'+w+'px;height:'+h+'px;left:'+w+'px;filter:alpha(opacity=40);-moz-opacity:0.4;"></div></div>';
			this.div = document.createElement("div");
			this.div.id = this.ele.id + "_hoverdiv";
			this.div.style.display="none";
			document.body.appendChild(this.div);
			
			addEvent(this.div, "mouseover", this.ondivmouseover.bind(this));
			addEvent(this.div, "mouseout", this.ondivmouseout.bind(this));
			
			addEvent(this.ele, "mouseover", this.onmouseover.bind(this));
			addEvent(this.ele, "mouseout", this.onmouseout.bind(this));
			addEvent(btnPrev, "mouseover", this.onmouseover.bind(this));
			addEvent(btnPrev, "mouseout", this.onmouseout.bind(this));
			addEvent(btnPrev, "click", this.onprev.bind(this));
			addEvent(btnNext, "mouseover", this.onmouseover.bind(this));
			addEvent(btnNext, "mouseout", this.onmouseout.bind(this));
			addEvent(btnNext, "click", this.onnext.bind(this));

			this.state = this.ele.id + "_div1";
		
			this.objXML = null;

			if (window.XMLHttpRequest) {
				this.objXML = new XMLHttpRequest();
			}
			else if (window.ActiveXObject) {
				this.objXML = new ActiveXObject("Microsoft.XMLHTTP");
			}	
			
			if (this.objXML) {
				this.objXML.onreadystatechange = this.ondata.bind(this);
			}
			this.objXML.open("GET", window.location.protocol + "//" + window.location.hostname + url, true);
			this.objXML.setRequestHeader("Accept-Charset", "iso-8859-9");
			this.objXML.setRequestHeader("Accept-Language", "tr");

			if(!MS.Browser.isIE) {
				this.objXML.setRequestHeader("Connection", "close");
			}
			this.objXML.send(null);
			
		}
	}, false);

	atlas.code30 = Class.create();
	Object.extend(atlas.code30.prototype, {
		

                code50: null,
		id: 0,
                fiy: "",
                haberid: "",
		code20: "",
		code10: "",
		code40: "",
		fiyatcode: 0,
		atlasfiyat1: 0,
		atlasfiyat2: 0,
		atlasfiyat3: 0,
		atlasfiyat4: 0,
		discount: 0,
		initialize: function(code50Id, fiId, fifiy, fihaberid, ficode20, ficode10, ficode40, fi, fi1, fi2, fi3, fi4 ) {
			this.code50 = code50Id;
			this.id = fiId;
                        this.fiy = fifiy;
                        this.haberid = fihaberid;
			this.code20 = ficode20;
			this.code10 = ficode10;
			this.code40 = ficode40;
			this.fiyatcode = fi;
			this.atlasfiyat1 = fi1;
			this.atlasfiyat2 = fi2;
			this.atlasfiyat3 = fi3;
			this.atlasfiyat4 = fi4;
                        
		}
	}, true);
	
