﻿function $(id){return document.getElementById(id);}

var modem = function(){};
modem.action=function(){this.k =function(s){return new modem.action.Object(s);}};

modem.action.Object=function(ObjectId)
{
    this.setTime=100;
    this.ObjectId = ObjectId;
    this.tabact=function(s,k){return new modem.action.tab(ObjectId,s,k);}
	this.imgtabact = function(s){return new modem.action.imgtab(ObjectId,s);}
	this.scrollTop = function(h){ return new modem.action.updown(ObjectId,h);}
}

modem.action.Object.prototype=
{
    Isnull:function(BcakCall)
    {
        if($(this.ObjectId)){BcakCall();}
        else
        {
            var tmplook = this;
            setTimeout(function(){tmplook.Isnull(BcakCall)},this.setTime);
        }
    },
    Onclick:function(evel)
    {   
        var tmp = this;
        this.Isnull(function(){$(tmp.ObjectId).onclick=function(){evel();}});
    }
}

modem.action.updown = function(objectID,h)
{
    this.warpId = objectID;
    this.height = h;
    this.mar = null;
}

modem.action.updown.prototype=
{
    initializtion:function(time)
    {
        var k = new modem.action.Object(this.warpId);
        var t = this;
        k.Isnull(function(){t.scrtop(time);});
    },
    scrtop:function(time)
    {
         var myDiv = document.createElement("div");
         var obj = $(this.warpId).children[0];
         myDiv.appendChild(obj);
         var MyObj = document.createElement(obj.tagName);
         myDiv.appendChild(MyObj);
         $(this.warpId).appendChild(myDiv);
         MyObj.innerHTML=obj.innerHTML;
         this.movetop($(this.warpId),obj,MyObj,time);
    },
    movetop:function(obj1,obj2,obj3,time)
    {
        var t = this;
        this.mar=setInterval(function(){t.Marquee(obj1,obj2,obj3,time);},1); 
        obj1.onmousemove=function(){clearInterval(t.mar);}
        obj1.onmouseout=function(){clearInterval(t.mar);t.mar=setInterval(function(){t.Marquee(obj1,obj2,obj3,time);},1);}
    },
    Marquee:function(obj1,obj2,obj3,time)
    {
        var t =this;
        if(obj3.offsetHeight-obj1.scrollTop<=0){ obj1.scrollTop-=obj3.offsetHeight;}else{obj1.scrollTop=obj1.scrollTop+1;}
        if(obj1.scrollTop%parseInt(this.height)==0){clearInterval(this.mar);this.mar=setTimeout(function(){t.movetop(obj1,obj2,obj3,time);},time); }
    }
}

modem.action.imgtab = function(objectID,objectTab)
{
	this.TabId  = objectID;
	this.TabTag = objectTab;
	this.time = null;
}

modem.action.imgtab.prototype=
{
	initializtion: function(tag1,tag2,css)
	{
		var k = new modem.action.Object(this.TabId);
		var t = this;
		k.Isnull(function(){t.imgact(tag1,tag2,css);})
	},
	imgact:function(tag1,tag2,css)
	{
	    var t = this;
		for(var i=0;i<$(this.TabId).children.length;i++)
		{
		    $(this.TabId).children[i].style.display='none';
		    $(this.TabTag).children[i].order=i;
	        $(this.TabTag).children[i].onmousemove=function(){t.imgactms(css,this.order);};
		    $(this.TabTag).children[i].onmouseout=function(){t.time=setTimeout(function(){t.settimes(css);},1000);}
		}
		$(this.TabId).children[i-1].style.display='';
		this.settimes(css);
	},
	settimes:function(css)
	{   
	    for(var i=0;i<$(this.TabId).children.length;i++)
		{
		    $(this.TabTag).children[i].className=$(this.TabTag).children[i].className.replace(css,"");
		    if($(this.TabId).children[i].style.display=='')
		    {
		       $(this.TabId).children[i].style.display='none';
		       var k =i;
		       if(k+1>3){k=-1;}
		       $(this.TabId).children[k+1].style.display='';
		       $(this.TabTag).children[k+1].className=css + $(this.TabTag).children[k+1].className;
		       break;
		    }
		}
		var t = this;
	    this.time = setTimeout(function(){t.settimes(css);},3000);
	},
	imgactms:function(css,d)
	{
	    clearTimeout(this.time);
	    if($(this.TabId).children[d].style.display=='')return;
	    for(var i=0;i<$(this.TabId).children.length;i++)
	    {
	        $(this.TabId).children[i].style.display='none';
	        $(this.TabTag).children[i].className=$(this.TabTag).children[i].className.replace(css,"");
	    }
	    $(this.TabId).children[d].style.display='';
	    $(this.TabTag).children[d].className=css+$(this.TabTag).children[d].className;
	}
}

modem.action.tab = function(ObjectId,TabTag,css)
{
    this.Tabid = ObjectId;
    this.TabTag = TabTag;
    this.objects = new Array();
    this.tabCss = css;
}

modem.action.tab.prototype=
{
    saert:function(objected)
    {
        var ob = objected;
        if(!ob){ob=$(this.Tabid);}
        for(var i=0;i<ob.children.length;i++)
        {
            if(ob.children[i].tagName==this.TabTag)
            {
                var obs = this;
                this.objects[this.objects.length]=ob.children[i];
                ob.children[i].onmousemove=function(){obs.tabactexec(this)};
            }
            else{this.saert(ob.children[i]);}
        }
    },
    tabactexec:function(objid)
    {
        var ob = this.objects;
        for(var i=0;i<ob.length;i++)
        {
            ob[i].className=ob[i].className.replace(" "+this.tabCss,"");
            ob[i].parentNode.children[ob[i].parentNode.children.length-1].style.display="none";
        }
        objid.className +=" "+this.tabCss;
        objid.parentNode.children[objid.parentNode.children.length-1].style.display="block";
    },
    sert:function()
    {
        var k = new modem.action.Object(this.Tabid);
        var t = this;
        k.Isnull(function(){t.saert()});
    },
    saertsettime:function(objectid)
    {
        var ob =objectid;
        if(!ob){ob=$(this.Tabid);}
        for(var i=0;i<ob.children.length;i++)
        {
            if(ob.children[i].tagName==this.TabTag)
            {
                var obs = this;
                ob.children[i].order = i;
                ob.children[i].onmousemove=function(){obs.imgact(this.order)};
            }
            else{this.saertsettime(ob.children[i]);}
        }
    }
}

modem.ajax=function(tjact,tjpage,str)
{
    this.tjact =  tjact;
    this.tjpage = tjpage;
    this.str   = str;
}
modem.ajax.prototype=
{
    newXMLHttpRequest:function()
    {
        var xmlreq=false;
         if(window.XMLHttpRequest){xmlreq=new XMLHttpRequest();} else 
         if(window.ActiveXObject){
          try {xmlreq=new ActiveXObject("Msxml2.XMLHTTP");} 
          catch(e1) {
            try {xmlreq=new ActiveXObject("Microsoft.XMLHTTP");} 
            catch(e2) {}}}
        return xmlreq;
    },
    fashx:function(callback)
    {
        var req=this.newXMLHttpRequest();
        var callbackHandler=this.getReadyStateHandler(req,callback);
        req.onreadystatechange=callbackHandler;
        req.open(this.tjact,this.tjpage,true);
        req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        req.send(this.str);
    },
    getReadyStateHandler:function(req,callback)
    {
        return function() {if(req.readyState==4) {if(req.status==200){callback(req.responseText)}else{}} else {}}
    }
}
