jQuery(document).ready(function () {
	c_sectionMenu = jQuery("#section-menu");	//cache obj for jquery
	c_sectionMenuContainer = jQuery("#section-menu-contianer");	//cache obj for jquery
	c_sectionMenuAutoPosition = jQuery("#section-menu-auto-position");	//cache obj for jquery
	
	/*Auto Absolute position menu from body tag, gets menu on top of all over site content*/
	if(c_sectionMenuAutoPosition.length>0) {
		jQuery("body").prepend(c_sectionMenuContainer);
		c_sectionListMenuAutoPositionFirst();
		jQuery(window).resize(function () { 
		    c_sectionListMenuAutoPosition();
		});
	
	}
});

function c_sectionListMenuAutoPositionFirst() {
	menuPos = c_sectionMenuAutoPosition.position();
	menuHeight = c_sectionMenuContainer.height();
	menuNewTop = menuPos.top - menuHeight;
	c_sectionMenuContainer.css("position","absolute");
	//c_sectionMenuContainer.css("top",menuNewTop+"px");
	c_sectionMenuContainer.css("left",menuPos.left+"px");
	c_sectionMenuContainer.css("display","block");	
}

function c_sectionListMenuAutoPosition() {
	menuPos = c_sectionMenuAutoPosition.position();
	menuHeight = c_sectionMenuContainer.height();
	menuNewTop = menuPos.top - menuHeight;
	c_sectionMenuContainer.css("position","absolute");
	c_sectionMenuContainer.css("z-index","10000");
	//c_sectionMenuContainer.css("top",menuNewTop+"px");
	c_sectionMenuContainer.css("left",menuPos.left+"px");
	c_sectionMenuContainer.css("display","block");
}

jQuery(document).ready(function()  {  
   if(jQuery("#EcomScroller").length>0) { 
    jQuery('#EcomScroller').show();
    jQuery('#EcomScroller').cycle({
        fx: 'scrollHorz',   
         timeout: 0 ,
         speed:   500,
        prev:    '#EcomControlsPrev',
        next:    '#EcomControlsNext'           
    });       
    }    
});

/*START ROTATOR*/
jQuery(document).ready(function()  {  
   if(jQuery("#RotatorBox").length>0) {    
   jQuery('#scroller').show();
   jQuery('#scrollerThumbs').show();
    jQuery('#scroller').cycle({
        fx:     'fade', 
        speed:  'slow', 
        timeout: 5000, 
        prev:    '#prev',
        next:    '#next',     
         pager:  '#scrollerThumbs', 
        pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#scrollerThumbs li:eq(' + idx + ') a'; 
        }                     
    });   
    }
    
});


/*END ROTATOR*/

/*START SCHEDULE*/
//http://www.deckerdev.com/blog/category/JQuery.aspx//
 function getTop() {
	// get the top of the content
	var top = jQuery('#scroll-content').css('top');
	return trimPx(top);
}

function getHeight(id) {
	// get the height, including padding
	var height = jQuery(id).height();
	var paddingTop = trimPx(jQuery(id).css("padding-top"));
	var paddingBottom = trimPx(jQuery(id).css("padding-bottom"));

	return height + paddingTop + paddingBottom;
}

function trimPx(value) {
	// remove "px" from values
	var pos = value.indexOf("px");
	if (pos != 0)
		return parseInt(value.substring(0, pos));
	else
		return 0;
}

var container;
var content;
var hidden;	// # of pixels hidden by the container

function setScrollerDimensions() {
	container = getHeight("#scroll-container");
	content = getHeight("#scroll-content");
	hidden = content - container;
}

function resetScroller() {
	setScrollerDimensions();
	jQuery('#scroll-content').css('top', 0);
}


jQuery(document).ready(function() {
if(jQuery("#scroll-controls").length>0) {
  jQuery('#scroll-controls').show(); 
    
    jQuery('.up-arrow').css("filter","alpha(opacity=50)");
    jQuery('.up-arrow').css("opacity","0.4");
                
	setScrollerDimensions();

	jQuery('#scroll-controls a.up-arrow').click(function() {
		return false;
	});

	jQuery('#scroll-controls a.down-arrow').click(function() {
		return false;
	});

	jQuery('#scroll-controls a.down-arrow').hover(
		function() {
			if (hidden > 0) {
				var current = getTop();
				jQuery('#scroll-content').animate({ top: -hidden }, Math.abs(current - hidden) * 5);
				jQuery('.down-arrow').css("filter","alpha(opacity=50)");
                jQuery('.down-arrow').css("opacity","0.4");	
                 jQuery('.up-arrow').css("filter","alpha(opacity=100)");
                jQuery('.up-arrow').css("opacity","1");
			}
		},
		function() {
			jQuery('#scroll-content').stop();
			  	  

		}
	);

	jQuery('#scroll-controls a.up-arrow').hover(
		function() {
			if (hidden > 0) {
				var current = getTop();
				jQuery('#scroll-content').animate({ top: "0" }, Math.abs(current) * 5);
				 jQuery('.up-arrow').css("filter","alpha(opacity=50)");
                jQuery('.up-arrow').css("opacity","0.4");
                jQuery('.down-arrow').css("filter","alpha(opacity=100)");
                jQuery('.down-arrow').css("opacity","1");	
			}
		},
		function() {
			jQuery('#scroll-content').stop();
				
		}
	);
}
    
});

/*END SCHEDULE*/






/*MORE MODULE*/
function thecarousel_initCallback(carousel) {
    
    jQuery('#thecarousel-next').click(function() {
        carousel.next();
       return false;
    });

    jQuery('#thecarousel-prev').click(function() {
        carousel.prev();
        return false;
    });
    
};
// Ride the carousel...
jQuery(document).ready(function() {
  jQuery('#MoreArea').show(); 
     jQuery("#thecarousel").jcarousel({      
        start:1,
        scroll: 1,     
        initCallback: thecarousel_initCallback,         
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });    
});
