(function ($, undefined) {

 $(function () {
 $(".Menu>div").mouseenter(function () {
 var j = $(this);
 var c = j.children("div");

 var tw = 960;

 var hl = j.position().left;
 var hw = j.outerWidth();
 var hc = hl + hw / 2;
 var dw = c.outerWidth();
 var dl;

 if ((hl + dw) < tw) {
 dl = 0;
 }
 else if (dw < (hl + hw)) {
 dl = hw - dw;
 }
 else {
 dl = -(dw * hl) / (960 - hw) + hw / 2;
 if (dl > 0) { dl = 0; }
 if (dl + dw < hw) { dl = hw - dw; };
 }
 c.css("left", dl + "px");

 });

 });

} (jQuery));





(function (horzScroll, $, undefined) {

 $.extend(horzScroll, {
 
 findClassInt : function ( node, startsWith, defaultValue ) {
 var len = startsWith.length;
 var hclasses = node.attr("class").split(" ");
 var val;
 for (var i=0;i<hclasses.length;i++) {
 if (hclasses[i].substr(0,len)==startsWith) {
 val = parseInt(hclasses[i].substr(len));
 return isNaN(val)?defaultValue:val;
 }
 }
 return defaultValue;
 },

 init: function () {

 var horz = $(this);
 var win = horz.children("div").css({ position: "relative", overflow: "hidden" });
 var scroll = win.children("div").css({ position: "absolute", left: 0, whiteSpace: "nowrap" });
 var left = horz.find(".Left");
 var right = horz.find(".Right");
 var winwidth = win.innerWidth();
 var scrollwidth = scroll.innerWidth();

 
 var duration = horzScroll.findClassInt(horz, "SpeedScroll", 200);
 var move = function (dir, auto) {
 var leftpos = parseInt(scroll.css("left"));
 
 if (dir==0&&auto) {
 if (leftpos==-scrollwidth + winwidth) {
 dir=1000;
 } else {
 dir=-1;
 }
 }

 var newleft = leftpos + dir * winwidth;
 if (newleft >= 0) {
 newleft = 0;
 if (!auto) left.addClass("disabled");
 }
 else {
 if (!auto) left.removeClass("disabled");
 }

 if (newleft <= -scrollwidth + winwidth) {
 newleft = -scrollwidth + winwidth;
 if (!auto) right.addClass("disabled");
 }
 else {
 if (!auto) right.removeClass("disabled");
 }

 if (leftpos != newleft) {
 scroll.animate({ left: newleft + "px" }, { duration: duration });
 }

 }
 
 if (horz.is("[class*=AutoScroll]")) {
 left.addClass("disabled");
 right.addClass("disabled");

 
 var delay = horzScroll.findClassInt(horz, "AutoScroll", 2000);
 
 
 setInterval( function() {
 move(0,true);
 }, delay);
 }
 else if (scrollwidth <= winwidth) {
 left.addClass("disabled");
 right.addClass("disabled");
 }
 else {
 move(0);

 left.addClass("disabled").unbind('click').click(function () {
 move(1);
 return false;
 });

 right.removeClass("disabled").unbind('click').click(function () {
 move(-1);
 return false;
 });
 }


 }
 });

 $(function () {
 $(".HorzScroll").each(horzScroll.init);
 });

} (window.horzScroll = window.horzScroll || {}, jQuery));

