function spin(steps, direction, element, velocity) {
	var step = parseInt(element.attr('step'), 10) || 0;
	var interval = setInterval(function() {
		element.css({backgroundPosition:steps[step]});
		step += direction;
		if (step == steps.length || step == -1) {
			step = Math.min(Math.max(step, 0), steps.length - 1);
			clearInterval(interval);
		};
		element.attr('step', step);
	}, velocity);
	return interval;
}

jQuery(document).ready(function($){
	var gullane = {
		init : function(){
			$('a.disabled').click(function(e){
				//e.preventDefault();
			});
			
			$('a[rel=external]').attr('target', '_blank');
		},
		spinning : function(){
			var intervalEntrada;
			var steps = ['left 0px', 'left -17px', 'left -34px', 'left -51px', 'left -68px'];
			var alturasub = ['65px','40px','40px','20px'];

			$('header .wrapper ul li').find('.submenu').each(function(index){
				$(this).parent().hover(function(){
					var plus = $(this).find('.plus');
					intervalEntrada = spin(steps, 1, plus, 40);
					$(this).find('ul').stop().css('height',alturasub[index]).animate({
						height:'show'
					},300);
				},function(){
					var plus = $(this).find('.plus');
					clearInterval(intervalEntrada);
					spin(steps, -1, plus, 40);
					$(this).find('ul').stop().animate({
						height:'hide'
					},200);
				});	
			})
		},
		check_flash : function(){
			var requiredMajorVersion = 10;
			var requiredMinorVersion = 0;
			var requiredRevision = 0;
			
			var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
			
			if (hasReqestedVersion) {
				gullane.flash_home();
			} else {
				$('#balls-animated').show();
			}
			
		},
		flash_home : function(){
			var swf = URL_BASE + 'swf/flash_topo.swf?'+Math.random();

			var flashvars = {
				URL_BASE:URL_BASE,
				LANGUAGE:LANGUAGE
			};

			var params = {
				quality:"high",
				scale:'noScale',
				wmode:'transparent'
			};

			var attributes = {
			  id: "flash_dz"
			};

			swfobject.embedSWF(swf, "flash_dz", "100%", 481, "10.0.0","expressInstall.swf", flashvars, params, attributes);
		}
	}
	
	gullane.init();
	gullane.spinning();
	gullane.check_flash();
	
});

