jQuery(document).ready(function () {
    var imgSize = jQuery('.banner_imgs ul li').size();
    var items = [];
    var ctr = 0;
    var indicators = [];
    jQuery('.banner_imgs ul li').each(function (index, item) {
        items[ctr] = jQuery(item);
        jQuery('#indicator').append("<a href='#'></a>");
        ctr++;
    });
    ctr = 0;
    jQuery('#indicator a').each(function (index, item) {
        indicators[ctr] = jQuery(item);
        ctr++;
    });
    var current_item = 0;
    var rotateImg = function () {
        jQuery('#indicator a').removeClass("hover");
        indicators[current_item].addClass("hover");
        jQuery('.banner_imgs ul li:visible').fadeOut("slow");
        items[current_item].fadeIn("slow");
        if ((current_item + 1) < imgSize) {
            current_item = current_item + 1;
        } else {
            current_item = 0;
        }
    }
    rotateImg();
    setInterval(
		function () {
		    rotateImg();
		},
		5000
	);
    jQuery('#indicator a').click(
        function () {
            current_item = jQuery(this).index();
            rotateImg();
        }
    );

    jQuery('li.item, li.current, li.c_leftHov, li.c_left').hover(
		function () { jQuery('ul.sub', this).stop(true, true).fadeIn("fast"); },
		function () { jQuery('ul.sub', this).stop(true, true).fadeOut("slow"); });
    jQuery('ul.sub li').hover(
		function () {
		    var pos = jQuery(this).offset();
		    var parentW = jQuery(this).innerWidth();
		    var menuW = jQuery('ul:first', this).innerWidth();
		    cWidth = jQuery(window).width();
		    var totalW = menuW + pos.left + parentW;
		    var mLeft = parentW;
		    if (totalW > cWidth) {
		        mLeft = (menuW * -1) - 4;
		    }
		    jQuery('ul:first', this).stop(true, true).fadeIn("fast");
		    jQuery('ul:first', this).css("margin-left", mLeft);
		},
		function () { jQuery('ul:first', this).stop(true, true).fadeOut("slow"); });
    jQuery('ul.sub li ul li').hover(
		function () {
		    var pos = jQuery(this).offset();
		    var parentW = jQuery(this).innerWidth();
		    var menuW = jQuery('ul:first', this).innerWidth();
		    cWidth = parseInt(document.documentElement.clientWidth);

		    var totalW = menuW + pos.left + parentW;
		    var mLeft = pos.left + parentW;
		    if (totalW > cWidth) {
		        mLeft = pos.left - (parentW + 2);
		    }
		    jQuery('ul:first', this).stop(true, true).fadeIn("fast");
		    jQuery('ul:first', this).offset({ left: mLeft });
		},
		function () {
		    jQuery('ul:first', this).stop(true, true).fadeOut("slow");
		});
    $('#fb_contents').fbWall({ id: '181206745355', accessToken: '223620411024880|fqbN-e5yLca4O__taX3lBJsSX2E' });
});
