// custom.js

// Stores browser version 
var ieVer = getInternetExplorerVersion();

(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

$('#message').customFadeIn('fast', function() {
   //no more fiddling with attributes here
});

function MenuAndMap() {
	this.time_trans = 100; // miliseconds
	this.item_classes = [];
	this.menu_selector_prefix = '';
	this.map_selector_prefix = '';
	this.img_srcs = [];
	this.img_x_pos = [];
	this.img_y_pos = [];
	this.addRegion = function(sClass, sImgSrc, iImgXPos, iImgYPos) {
		this.item_classes.push(sClass);
		this.img_srcs.push(sImgSrc);
		this.img_x_pos.push(iImgXPos);
		this.img_y_pos.push(iImgYPos);
	}
	this.init = function() {
		var i;
		for(i = 0; i < this.item_classes.length; i++) {
			var sClass = this.item_classes[i];
			var sImgSrc = this.img_srcs[i];
			var x = this.img_x_pos[i];
			var y = this.img_y_pos[i];
			$(this.map_selector).append('<img class="MapRegion '+sClass+'" style="left: '+x+'px; top: '+y+'px;" src="'+sImgSrc+'" />');
			var jqMenuItem = $(this.menu_selector_prefix + sClass);
			var jqMapItem = $(this.map_selector_prefix + sClass);
			jqMenuItem.data('map', jqMapItem).data('time_trans', this.time_trans);
			jqMenuItem.hover(
				 function() {
					 // if IE7 or less don't use fadein
					  if ( ieVer > -1 && ieVer <= 7.0)
					  {
						$(this).stop(true, false).data('map').show();
					  } 
					  else {
					  	var iTimeTrans = $(this).data('time_trans');
						$(this).stop(true, false).data('map').delay(iTimeTrans / 2).fadeIn(iTimeTrans);
					  }
				}
				,function() {
					// if IE7 or less use instant fadeout
					if ( ieVer > -1 && ieVer <= 7.0)
					  {
						$(this).stop(true, false).data('map').fadeOut(0);
					  } 
					  else {
						$(this).stop(true, false).data('map').fadeOut($(this).data('time_trans') / 2);
					  }
				}
			);
		}
	};
}


function SlideShow() {
	this.timeout = 4000;
	this.speed = 1000;
	this.container_selector = "";
	this.button_selector = "";
	this.init = function() {
		var jqSlider = $(this.container_selector);
		var jqButtons = $(this.button_selector);
		jqSlider.find('> div').show();
		jqSlider.cycle( { timeout: this.timeout, speed: this.speed, pause: 1, random: 0 } );
		jqButtons.data('slider', jqSlider);
		jqButtons.each( function(index) {
			index = index % $(this).data('slider').find('> div').length;
			$(this).click( function() {
				$(this).data('slider').cycle(index);
			} );
		} );
	}
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
