//اللهم لا علم لنا الا ما علمتنا
//  Advanced  Javascript
//		PHP0@hotmail.com And Almhajer@hotmail.com
//   Class  BK  Javascript
//  Extand Elemnts.js
//


BK.Animation = new function() {


    return{


    //@Example   //BK.Animation.Opacity('ss',100,0,1000) ;

        Opacity:function (id, opacStart, opacEnd, millisec) {
            //speed for each frame
            var speed = Math.round(millisec / 100);
            var timer = 0;

            //determine the direction for the blending, if start and end are the same nothing happens
            if (opacStart > opacEnd) {
                var i = 0;
                for (i = opacStart; i >= opacEnd; i--) {
                    setTimeout("BK.Animation.Change_Opacity(" + i + ",'" + id + "')", (timer * speed));
                    timer++;
                }
            } else if (opacStart < opacEnd) {
                for (i = opacStart; i <= opacEnd; i++)
                {
                    setTimeout("BK.Animation.Change_Opacity(" + i + ",'" + id + "')", (timer * speed));
                    timer++;
                }
            }
        },

    //change the opacity for different browsers
        Change_Opacity:function (opacity, id) {
            var object = BK.Elements.Get(id).style;
            object.opacity = (opacity / 100);
            object.MozOpacity = (opacity / 100);
            object.KhtmlOpacity = (opacity / 100);
            object.filter = "alpha(opacity=" + opacity + ")";
        }   ,



    //@Example   BK.Animation.Shift_Opacity('ss',1000) ;

        Shift_Opacity:function (id, millisec) {
            //if an element is invisible, make it visible, else make it ivisible
            if (BK.Elements.Get(id).style.opacity == 0) {
                this.Opacity(id, 0, 100, millisec);
            } else {
                this.Opacity(id, 100, 0, millisec);
            }
        },

        Blend_Image:function (divid, imageid, imagefile, millisec) {
            var speed = Math.round(millisec / 100);
            var timer = 0;

            //set the current image as background
            BK.Elements.Get(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

            //make image transparent
            this.Change_Opacity(0, imageid);

            //make new image
            BK.Elements.Get(imageid).src = imagefile;

            //fade in image
            var i = 0;
            for (i = 0; i <= 100; i++) {
                setTimeout("BK.Animation.Change_Opacity(" + i + ",'" + imageid + "')", (timer * speed));
                timer++;
            }
        } ,

    //@Example   BK.Animation.Current_Opacity('ss',100,10000);

        Current_Opacity:function (id, opacEnd, millisec) {
            //standard opacity is 100
            var currentOpac = 100;

            //if the element has an opacity set, get it
            if (BK.Elements.Get(id).style.opacity < 100) {
                currentOpac = BK.Elements.Get(id).style.opacity * 100;
            }

            //call for the function that changes the opacity
            this.Opacity(id, currentOpac, opacEnd, millisec)
        },


    //@Example BK.Animation.Set_Width('ss',10,200);

        Set_Width:function (id, Start, Finsh) {


            //speed for each frame
            var speed = Math.round(500 / 100);
            var timer = 0;

            //determine the direction for the blending, if start and end are the same nothing happens
            if (Start > Finsh) {
                var i = 0;
                for (i = Start; i >= Finsh; i--) {
                    setTimeout("BK.Animation.Set_Width_Element(" + i + ",'" + id + "')", (timer * speed));
                    timer++;
                }
            } else if (Start < Finsh) {
                for (i = Start; i <= Finsh; i++)
                {
                    setTimeout("BK.Animation.Set_Width_Element(" + i + ",'" + id + "')", (timer * speed));
                    timer++;
                }
            }

        },

    //@ Example   BK.Animation.Set_High('ss',10,200);

        Set_High:function (id, Start, Finsh) {
            //speed for each frame
            var speed = Math.round(500 / 100);
            var timer = 0;

            //determine the direction for the blending, if start and end are the same nothing happens
            if (Start > Finsh) {
                var i = 0;
                for (i = Start; i >= Finsh; i--) {
                    setTimeout("BK.Animation.Set_High_Element(" + i + ",'" + id + "')", (timer * speed));
                    timer++;
                }
            } else if (Start < Finsh) {
                for (i = Start; i <= Finsh; i++)
                {
                    setTimeout("BK.Animation.Set_High_Element(" + i + ",'" + id + "')", (timer * speed));
                    timer++;
                }
            }

        },


        Set_Width_Element:function (Width, id) {

            var object = BK.Elements.Get(id);
            object.style.width = Width + "px";
        },

        Set_High_Element:function (Width, id) {

            var object = BK.Elements.Get(id);
            object.style.height = Width + "px";
        }

    }


}
