if (typeof(TCC) == 'undefined') {
	TCC		= {};
	TCC.UI	= {};
}

TCC.UI.Global	= function()
{
	var init	= function() {
		imageSwitch();
		slidesIn();
		//preload("../images/rollover/1.jpg","../images/rollover/2.jpg","../images/rollover/60.jpg","../images/rollover/53.jpg");
        for(var i = 0; i<arguments.length; i++)
	    {
	        preload(arguments[i]);
	    }
	}
	
	var preload = function() {
	  for(var i = 0; i<arguments.length; i++)
	  {
	    $("<img>").attr("src", "../images/rollover/"+arguments[i]+".jpg");	   
	  }
	}
	
	
	var imageSwitch = function() {
		
		$("#switch > li > a").mouseover(function() {
            if($.browser.msie && $.browser.version == '6.0') {
            } else {            
			    var theid = this.id
			    var newimage = theid+'.jpg';
                $("#feature-box").css("background-image","url(../images/rollover/"+newimage+")");					      			
            }                
		}
			
		);
		
	}
	    
	var slidesIn = function() {
		var imagearray = new Array();
		//read in the xml.		
		$.get(xmlFile,{},function(xml) { 
			$('ITEM',xml).each(function() {
				var img = {};
				img.path = this.getAttribute('pic');
				img.cur = false;
				imagearray[imagearray.length] = img;				
			});
		
			
		
		
			var h = $("#slideshow-box").height();
			var w = $("#slideshow-box").width();
			$("#slideshow-box").prepend('<div id="smokescreen" style="position: absolute; height: '+h+'px; width: '+w+'px; background-color: black;"></div>');
			
			if($.browser.msie && $.browser.version == '6.0') {
				$("#slideshow-box").css('position', 'relative').prepend('<div id="ie6mustdie" style="width:55px; overflow: hidden; height: '+(h-25)+'px; position: absolute; right:-3px; top: 0; z-index:101;"><img src="assets/images/feature-top.gif" style="position: absolute; top: 0; right:0;" /></div>');
			}
			
			var showSlide = function() {
				var thisimage = false;
				
				for(var i = 0; i < imagearray.length; i++) {
					if(imagearray[i].cur == true) {
					    if($.browser.msie && $.browser.version == '6.0') {
						    if(imagearray[0]) {
							    thisimage = imagearray[0];
							    imagearray[i].cur = false;
							    thisimage.cur = true;
						    }
						    break;
					    } else {
						    if(imagearray[i+1]) {
							    thisimage = imagearray[i+1];
							    imagearray[i].cur = false;
							    thisimage.cur = true;
						    } else {
							    imagearray[i].cur = false;
							    thisimage = imagearray[0];
							    imagearray[0].cur = true;							
						    }
						    break;
					    }
					}
				}
				if(!thisimage) {
					thisimage = imagearray[0];
					imagearray[0].cur = true;
				}
				
				$("#smokescreen").fadeIn(2000, function() {
					
					$("#slideshow-box").css("background-image","url("+thisimage.path+")");
					if($.browser.msie && $.browser.version == '6.0') {
					    $("#smokescreen").fadeOut(100, function(){
						    //showSlide();
					    });					    
					} else {
					    $("#smokescreen").fadeOut(3000, function(){
						    showSlide();
					    });
					}
				});
		
			}
			showSlide();
					
		
		});
		
			
	}	    
	    
	return {
		init: init
	}
	
}();

//jQuery(function($) { TCC.UI.Global.init(); });
