﻿//<![CDATA[

/*---------------------
 * OBJECT - IWANTTO
 *---------------------*/
gai.iwantto = function(){
    
    function init() {
        var iwt_parentid = 1;
        var iwt_runningid = 1;
        $j(".iwantto").each(function(){
            var mainid = "iwtcontainer"+iwt_parentid;
            var $this = $j(this);
            $j("#"+ this.id +" > ul")
                .attr("id",mainid)
                .attr("old-color",$this.find("li > h3 > a").css("color"))
                .attr("old-background",$this.find("li:last").css("background-color"))
                .attr("position","iw"+iwt_runningid); //give parent an id
            $j("#"+ this.id +" > ul > li").each(function(){
                var tempid = "iw"+iwt_runningid;
                $j(this).attr("id","iw"+iwt_runningid)
                    .bind("mouseenter",function(){
                        //$j("#"+ this.id +" h3 > a").css("color","#000")
                        change(mainid ,tempid);
                });
                iwt_runningid += 1;
            });
            iwt_parentid += 1;
        });
    };
    
    function change(mainid,id) {
        var $mainBox = $j("#"+ mainid);
        var $oldBox = $mainBox.find("#"+$mainBox.attr("position"));
        var $newBox = $mainBox.find("#"+id);
        
        $oldBox.find("h3 > a").css("color", $mainBox.attr("old-color"));
        $oldBox.css("background-color", $mainBox.attr("old-background"));
        $newBox.find("h3 > a").removeAttr("style");
        $newBox.removeAttr("style");
        
        $mainBox.attr("position",id);
    };
    
    return{init:init,change:change}
    
}(gai);


/*---------------------
 * OBJECT - ACCORDION
 *---------------------*/
gai.accordion = function(){

    function init() {
        $j(".accordion").each(function(){
            var runningid = 1;
            var mainid = this.id;
            $this = $j(this);
            
            $j(this).attr("animated","false")
                 .attr("old-color",$j(this).find("ul > li > h3 > a").css("color"))
                 .attr("old-bgcolor",$j(this).find("ul > li > h3").css("background-color"))
                 .attr("old-bgposition","left top")
                 .attr("position","gaiAccordion"+runningid);
                         
            //reset default style
            $j("#"+ this.id +" > ul > li > ul").each(function(){
                $j(this).attr("defaultHeight",$j(this).height());
            });
            
            
            //styling for last-child in case browser does not support CSS3
            $j("#"+ this.id +" > ul > li:last").addClass("last-child");
            $j("#"+ this.id +" > ul > li:last > ul").addClass("hide");
            
            $j("#"+ this.id +" > ul > li").each(function(){
                var tempid = "gaiAccordion"+runningid;
                
                $j(this).attr("id",tempid);
                //event of mouseenter
                $j("#"+ this.id +" h3").bind("mouseenter",function(){
                    change(mainid ,tempid);
                });
                $j("#"+ this.id +" h3 > a").attr("href","javascript:;");
                runningid += 1;
                
                //$j("#"+ this.id +" > ul").animate({height: 0}, { duration:10, easing:'easeOutQuint',complete:function(){} });
                $j("#"+ this.id +" > ul").css("height","0px");
                
                if($j(this).hasClass("last-child")) {
                    $j("#"+ this.id +" > ul").css("display","none");
                }
            });
            
            $j("#"+ this.id +" > ul > li > ul:first").animate({height: $j("#"+ this.id +" > ul > li > ul:first").attr("defaultHeight")+"px"}, { duration:10, easing:'easeOutQuint',complete:function(){} });        
            
        });
    };
    
    function change(id,subid) {
        $debugtimer(true,"accordion.change("+id+","+subid+")");
        
        var $this = $j("#"+ id);
        var animated = $this.attr("animated");
        var position = $this.attr("position");

        if((animated=="false")&&(position != subid)) {
            $j("#"+ id).attr("animated","false");
            $j("#"+ id).attr("position", subid);
            
            $j("#"+ position + " h3 > a").css("color",$j("#"+ id).attr("old-color"));
            $j("#"+ position + " h3").css("background-position",$j("#"+ id).attr("old-bgposition")).css("background-color",$j("#"+ id).attr("old-bgcolor"));
            $j("#"+ subid + " h3 > a").removeAttr("style");
            $j("#"+ subid + " h3").removeAttr("style");
            
            if($j("#"+ position +" ul").attr("defaultHeight") == $j("#"+ subid +" ul").attr("defaultHeight")) {
                //$j("#"+ id).css("height", $j("#"+ id).height()+"px");
            }
            else {$j("#"+ id).css("height", "auto");}
            
            $j("#"+ position +" ul").animate({height : 0}, { queue:false, duration:700, easing:'easeOutCubic',complete:function(){
                $j("#"+ id).attr("animated","false");
                if($j("#"+ position).hasClass("last-child")) { $j("#"+ position +" ul").css("display", "none"); }
            } });
            
            $j("#"+ subid +" ul").css("display", "block");
            $j("#"+ subid +" ul").removeClass("hide");
            $j("#"+ subid +" ul").animate({height : $j("#"+ subid +" ul").attr("defaultHeight")+"px"}, { queue:false, duration:700, easing:'easeOutCubic',complete:function(){$j("#"+ id).attr("animated","false");} });
        }
        
        $debugtimer(false,"accordion.change("+id+","+subid+")");
    };
    
    return{init:init,change:change}

}(gai);


/*------------------------
 * OBJECT - BANNER SLIDER
 *------------------------*/
gai.banner = function(){

    function init() {
    };
    function change() {
    };
    return{init:init,change:change}

}(gai);

/*----------------------------
 * OBJECT - AUTO CLEAR TEXTBOX
 *----------------------------*/
gai.autotextbox = function () {

    function init(area) {
        var $this;
        var tempValue;
        $j(area + " .autoclear").each(function () {
            $this = $j(this);
            tempValue = $this.val();
            $this.attr("data-defaultValue", tempValue);
            $this.focus(function (tempValue) { gai.autotextbox.change("#" + $j(this).attr("id"), "focus", $j(this).attr("data-defaultValue")); });
            $this.blur(function (tempValue) { gai.autotextbox.change("#" + $j(this).attr("id"), "blur", $j(this).attr("data-defaultValue")); });
            $debug("gai.autotextbox.init(" + area + ")" + $this.attr("id") + " " + tempValue);
        });
    };
    function change(id, actionType, defaultValue) {
        $debugtimer(true, "gai.autotextbox.change(" + id + "," + actionType + "," + defaultValue + ")");
        var $this = $j(id);
        var tempValue = $j.trim($this.val());

        switch (actionType) {
            case "focus":
                if (tempValue == defaultValue) { $this.val(""); } //$debug("checkTextbox() : focus");
                break;
            case "blur":
                if (tempValue == "") { $this.val(defaultValue); } //$debug("checkTextbox() : blur");
                break;
            default:
                return false;
        }
        $debugtimer(false, "gai.autotextbox.change(" + id + "," + actionType + "," + defaultValue + ")");
    };
    return { init: init, change: change }

} (gai);




//gai.iwantto.init();
gai.accordion.init();
//gai.autotextbox.init("body");


//~AUTO INITIALIZATION
//$j(function () {

//    $j("select#search-filter").selectmenu({ style: "dropdown" });

//    //~SLIDER
//    $j(".slider").each(function () {
//        var maxposition = $j("#" + this.id + " .manual_slider li").size();
//        var $this = $j(this);

//        $this.attr("animated", "false");
//        $this.attr("position", "0");
//        $this.attr("maxposition", maxposition);
//    });

//});

//]]>
