﻿/// <reference path="jquery-1.2.6.js" />
var SupplierExmenu = {
    _width : 768,
    _state : false,
    _speed : 700,
    bind: function() {
        $.scrollTo.defaults.axis = 'x';

        $(".scrollRight").click(function() {
            $.scrollTo('+=730',SupplierExmenu._speed); //305+768+60
        });

        $(".scrollLeft").click(function() {
            $.scrollTo('-=730',SupplierExmenu._speed);//305+768+60
        });
    },
    showAgentIntro:function(evt, id) {
       if (SupplierExmenu._state == true) return;
        SupplierExmenu._state = true;
        var srcObj = evt.target || evt.srcElement;
        var parentObj = srcObj;
        if (SupplierExmenu["intropanel" + id] != null) {
            $(SupplierExmenu["intropanel" + id]).animate({ left: "-=0px" }, SupplierExmenu._speed, function() {
                  SupplierExmenu["intropanel" + id] = srcObj;
                  SupplierExmenu.openIntro(id, parentObj);
                  SupplierExmenu._state = false;
            });
            $("#introPanel" + id).html("<div style='width: 37px; height: 37px; position: absolute; top: 45%; left: 45%; background: url(images/loading.gif)'>");
        }
        else {
            SupplierExmenu["intropanel" + id] = srcObj;
            SupplierExmenu.openIntro(id, parentObj);
            SupplierExmenu._state = false;
        }
        
    },
    openIntro: function(id, parentObj) {
        var obj = $("#introPanel" + id);
        if (obj.width() == 0) {
            $("#mid").animate({ width: "+=" + SupplierExmenu._width + "px" }, SupplierExmenu._speed);
           // $(".RightSidebar").animate({ width: "+=" + SupplierExmenu._width + "px" }, SupplierExmenu._speed);
            obj.animate({ width: SupplierExmenu._width + "px" }, SupplierExmenu._speed,
                function() {
                    SupplierExmenu.loadIntro(id);
                    $.scrollTo(SupplierExmenu.absPoint(parentObj).x - 150, SupplierExmenu._speed, { axis: 'x' });
                }
            );
        }
        else {
       
            SupplierExmenu.loadIntro(id);
        }
    },
   absPoint: function(obj) {
        var x = obj.offsetLeft;
        var y = obj.offsetTop;
        while (obj = obj.offsetParent) {
            x += obj.offsetLeft;
            y += obj.offsetTop;
        }
        return { "x": x, "y": y };
    },
    AgentTemplate: '<div  class="introPanel" style=" width: 768px;">\
                    <div  style="width: 50px; height: auto; position: absolute; top: 10px; left: 710px;">\
  	                  <a href="#" onClick="return false;" id="ClosePanel" class="exunc_nav">Close</a>\
                    </div>\
                    <div class="IntroDiv">\
                      <div class="AgentIntro">\
                      </div>\
                    </div>\
                  </div>',
       
    
    loadIntro: function(id) {
        var obj = $("#introPanel" + id);
        obj.html("<div style='width: 37px; height: 37px; position: absolute; top: 45%; left: 45%; background: url(images/loading.gif)'>");
        var val = $(SupplierExmenu.AgentTemplate);
        val.find("#ClosePanel").click(function() { SupplierExmenu.closeIntro(id); });
        val.find(".AgentIntro").append($("#content"+id).html());
        obj.html(val);
        if($("#introPanel"+id+" .AgentIntro").height()>415){
          $("#introPanel"+id+" .IntroDiv").css("overflow-y","scroll");
        }
    },
    
    
     closeIntro: function(id) {
        SupplierExmenu._state = true;
        $(SupplierExmenu["intropanel" + id]).animate({ left: "-=146px" }, SupplierExmenu._speed, function() { SupplierExmenu["intropanel" + id] = null; });
        var obj = $("#introPanel" + id);
        obj.animate({ width: "0px" }, SupplierExmenu._speed, function() { obj.html(""); });
        //$(".RightSidebar").animate({ width: "-=" + SupplierExmenu._width + "px" }, SupplierExmenu._speed);
        $("#mid").animate({ width: "-=" + SupplierExmenu._width + "px" }, 800, function() { SupplierExmenu._state = false; });
    }
      
      
      
   
    
}
