//fix background image flickering in IE

/*@cc_on 
	@if (@_win32)
	try {
	  document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
	@end
@*/
var fcScroller = {
	init : function(o){
		var $scrollWrapper = $(".Inner");
		// the viewport
		$(".Inner ul").css("position","absolute");
		//make sure we can move it inside the wrapper
		var $scrollItemWidth = $(".Inner .item").width();
		//get the width and add 16 pixels for the padding
		var $scrollTotalItems = $(".Inner .item").length;
		//get the total amount ofitems in the list
		//recalculate what the total width should be
		var $viewableArea = $(".Inner").width();
		var $thewidth = 0;
		$(".Inner ul li img").each(function() {
			$thewidth += $(this).width()+10;
		});
		//the area that should be viewable
		($thewidth > $viewableArea) ? enableSlider() : $scrollWrapper.css("width","auto");	
		//if there are more then 5 items make the scrollbar, otherwise default to normal	
		function enableSlider(){
			$(".Inner ul").width($thewidth);
			//resize the width of the list
			$('#scroller').css("display","block");
			//show the scroller
			//$scrollWrapper.height($(".Inner ul").outerHeight());
			//recalculate the height of the wrapper
			var slider = new $.ui.slider($('#scroller')[0],{
						minValue:0,
						//stepping: $scrollTotalItems,
						maxValue: ($thewidth-$viewableArea), 
						//make the maximum value the totalwidth of items minus the viewable area so that it scrolls the right amount
						startValue: 0,
						//where the slider should be when is starts up 
						slide: function(e,ui) {
							$(".Inner ul").css({"left": - Math.round((ui.value))});			
						}
			});
		}
        		
	}
}

function allImagesLoaded() {
    var imagesloaded = 1;
    var images = document.images;
    for (var i = 0;i<images.length;i++) {
        if(images[i].complete == false) {
            imagesloaded = 0;
        }
    }
    return imagesloaded;
}

function TryOut() {
	if(allImagesLoaded() == 1) {
	    fcScroller.init();
	} else {
		var Try = setTimeout('TryOut();', 200);
	}
}

$(document).ready(function(){
	TryOut();
});

