﻿if (typeof(MEET2) == 'undefined') {
	MEET2		= {};
	MEET2.UI	= {};
}

MEET2.UI.Global	= function()
{
	var init	= function() {
		imageSwitch();
		slidesIn();
		preload("");
	}
	
	var preload = function() {
	  for(var i = 0; i<arguments.length; i++)
	  {
	    $("<img>").attr("src", arguments[i]);
	  }
	}
	
	
	var imageSwitch = function() {
		
		$("#switch").mouseover(function() {
			
			var theid = this.id
			var newimage = theid+'.jpg';
			$("#feature-box").css("background-image","url(assets/images/"+newimage+")");
		}
			
		);
		
	}
	
	var slidesIn = function() {
		var imagearray = new Array();
		//read in the xml.
		$.get(venueXmlFile,{},function(xml) { 
			$('ITEM',xml).each(function() {
				var img = {};
				img.path = this.getAttribute('pic');
				img.cur = false;
				imagearray[imagearray.length] = img;
			});
		
			
    		if (imagearray.length>0) {
    		
			    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: white;"></div>');
    			
			    if($.browser.msie && $.browser.version == '6.0') {
				    $("#slideshow-box").css('position', 'relative').prepend('<div id="ie6mustdie" style="width:0px; overflow: hidden; height: '+(h-25)+'px; position: absolute; z-index:101;"><img src="../images/venue_mask.gif" style="position: absolute; top: 0; right:0; width:656px; height:243px;" /></div>');
			    }
    			
			    var showSlide = function() {
				    var thisimage = false;
				    for(var i = 0; i < imagearray.length; i++) {
					    if(imagearray[i].cur == true) {
						    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(4000, function() {
    					
					    $("#slideshow-box").css("background-image","url("+thisimage.path+")");
					    $("#smokescreen").fadeOut(3000, function(){
						    showSlide();
					    });
				    });
    		
			    }
			    showSlide();
    			
			}
			
		});
					
	}
	
	return {
		init: init
	}
	
}();

jQuery(function($) { MEET2.UI.Global.init(); });