window.addEvent('domready', function() {
	
var subs = 60;
if($('logga') != null ){
$('logga').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop();
		
		
	
		this.set('send', {onComplete: function(response) { 
			// sätt inloggningsrutan till något.
			var loggad = "" + response;
			
				if(loggad.length > 1  ) {
					alert("du har loggat in");
				
					window.location = "/intranet/index";

				}else {
					alert("Fel lösenord eller användare");
					}
		}});
		//Send the form.
		this.send();
	});
}

	/*
		$('shopping').addEvents({
			'mousedown': function(){
				// Always sets the duration of the tween to 1000 ms and a bouncing transition
				// And then tweens the height of the element
				$('subs').setStyle('display','none');
				
				$('subs').setStyle('display','');
				
				$('subs').set('tween', {
				duration: 500,
				transition: Fx.Transitions.Sine.easeInOut // This could have been also 'bounce:out'
			}).tween('height', '250px');
				$('subs').innerHTML = "<img src='/images/load.gif' style='margin: 120px 100px 100px 240px'>";
				setTimeout("CollectData(1);", "2000");
			}
		}); 
		$('rest').addEvents({
			'mousedown': function(){
				// Always sets the duration of the tween to 1000 ms and a bouncing transition
				// And then tweens the height of the element
				$('subs').setStyle('display','none');
				$('subs').setStyle('display','');
				
				$('subs').set('tween', {
				duration: 500,
				transition: Fx.Transitions.Sine.easeInOut // This could have been also 'bounce:out'
			}).tween('height', '250px');
				$('subs').innerHTML = "<img src='/images/load.gif' style='margin: 120px 100px 100px 240px'>";
				setTimeout("CollectData(2);", "2000");
			}
		});

	


	
	
var list   = $$('#meny li a');


list.each(function(element) 
{

	
	element.addEvent('mouseenter', function()
	{
		var size = element.getCoordinates();
	
		if(element.id == "home" || element.id == "find" || element.id == "card" || element.id == "service" || element.id == "info" || element.id == "north"){
			$('submeny').setStyle("display","none");
			
		}else {
			GetMeny(element.id);
			$('submeny').setStyle("display","");
			$('submeny').innerHTML = "";
		$('submeny').setStyle("left",size.left);
		$('submeny').setStyle("top",size.top+15);
		$('submeny').setStyle("width",220);
				

		}


	});
 
	element.addEvent('mouseleave', function()
	{
		
	});
 
});

$('meny').addEvent('mouseleave', function()
	{
		
		$('submeny').addEvent('mouseenter', function()
			{
		
				$('submeny').setStyle("display","");
				var subs   = $$('#submeny a');
				var stop = 0;
				subs.each(function(element) 
				{
					element.addEvent('mouseenter', function()
					{
						var size = element.getCoordinates();
							$('submeny').setStyle("display","");
							
							//$('subsubmeny_'+element.id).innerHTML = "";
							$('subsubmeny '+element.id).setStyle("display","");
							//GetSubMeny(element.id);
							hideSubs(element.id);
							$('subsubmeny '+element.id).setStyle("z-index","1000");
							
							$('subsubmeny '+element.id).setStyle("left",size.left+160);
							$('subsubmeny '+element.id).setStyle("top",size.top-30);
							$('subsubmeny '+element.id).setStyle("width",260);
							
							stop = 1;
					});
					element.addEvent('mouseleave', function()
						{
						hideSubs(element.id);
							var stuff = $('subsubmeny '+element.id);
							
							stuff.addEvent('mouseenter', function()
							{
							hideSubs(element.id);
							$('subsubmeny '+element.id).setStyle("display","");
							});
							stuff.addEvent('mouseleave', function()
							{
							$('subsubmeny '+element.id).setStyle("display","none");
							});
							
							
							
						});
					if(stop == 1){
						event.stop();			
					}
				});		
				
			});
		$('submeny').addEvent('mouseleave', function()
			{
					
				//$('submeny').fade.bind($('submeny'), [0]);
				//hideSubs(null);
				//$('submeny').setStyle("display","none");
					

				
			});
		
					
				
				
			
	});


	$('content').addEvent('mouseenter', function()
			{
				hideSubs(null);
				$('submeny').setStyle("display","none");
		});

               $('container').addEvent('mouseenter', function()
			{
				hideSubs(null);
				$('submeny').setStyle("display","none");
		  });
	function hideSubs(id){

		for (var i = 0;i<=subs;i = i+1) {
			if(i != id){
				if($('subsubmeny '+i) != null){
			$('subsubmeny '+i).setStyle("display","none");
				}
			}
			if(i == id){
			$('subsubmeny '+i).setStyle("display","");
			}
		}

	}

*/


	/* ----------Config Vars FÖR LOGGO SLIDER----------- */
		
	var slideTimer2 = 8000;  //time between slides (1 second = 1000), a.k.a. the interval duration
	var transitionTime2 = 2000; //transition time (1 second = 1000)
	var items2 = $$('.slide_image');  //Get array of elements for sliding
	
	var ypos2 = 0;
	/* --------end config vars-------- */
	
	//Setup positions
	items2.each(function(element, index) {
		
		//since the viewer obviously has javascript on, we can remove the 'first_item' class
		if(index == 0){
			element.removeClass('first_slide');
			element.setStyle('left', "0");
			element.setStyle('top','0');
			//element.setStyle('overflow','hidden');
		}
		else{
			element.setStyle('top',0);			
			ypos2 = ypos2 - 0;				
			element.setStyle('left', "0");
			element.setStyle('opacity', "0");
			//element.setStyle('overflow','hidden');
		}
	
	});
	//end setup
	
	//Slider Stuff
	var slideFunction2 = new function() {
		
		var numItems = items2.length;  //get number of slider items
		var itemNum = 0;  //initialize a variable to hold the current slide index
		
		var slideIt2 = function(){ 
			
			//get item to slide out
			var curItem = items2[itemNum];  
			//curItem.setStyle('overflow','hidden');
			//change index
			if(itemNum < (numItems - 1)){
				itemNum++; 
			}
			else{
				itemNum = 0;
			}
			
			//now get item to slide in using new index
			var newItem = items2[itemNum];
			
			//newItem.setStyle('overflow','hidden');
			//set up our animation stylings for out and in motions (note:  Fx.Styles does NOT exist in moo 1.2, so we must use Fx.Morph or Fx.Tween)
			var item_in = new Fx.Morph(newItem, {
				     duration: transitionTime2, 
				     transition: Fx.Transitions.Quad.easeInOut, 
				     wait:false
			});
			
			var item_out = new Fx.Morph(curItem, {
				     duration: transitionTime2, 
				     transition: Fx.Transitions.Quad.easeInOut, 
				     wait:false
			});
			
			//we will set a beginning value here
			//this is so that it gives the illusion of continuous motion from one direction, even after the first cycle of items
			item_in.start({
			'left': [10, 0],
			'opacity':[0,1]
			});
			
			//no beginning values needed, since we always want to push the old item out to the left
			item_out.start({
			'left': '-10',
			'opacity':[0]
			});
			
		};
		
		//call the function, periodically  (note: the interval period is defined at the top of this file)
		slideIt2.periodical(slideTimer2, this); 
	}


// end of DOOOOOM

});

function GetSubMeny(id){

	var req = new Request.HTML({url:'http://city.comotion.se/index/submeny/'+id, 
				onSuccess: function(html) {
					//Clear the text currently inside the results div.
					$('subsubmeny').innerHTML = "";
				
					//Inject the new DOM elements into the results div.
					$('subsubmeny').adopt(html);
				},
				//Our request will most likely succeed, but just in case, we'll add an
				//onFailure method which will let the user know what happened.
				onFailure: function() {
					$('subsubmeny').set('text', '');
		}
	});

req.send();



}
function GetMeny(id){
	var req = new Request.HTML({url:'http://city.comotion.se/index/meny/'+id, 
				onSuccess: function(html) {
					//Clear the text currently inside the results div.
					$('submeny').innerHTML = "";
				
					//Inject the new DOM elements into the results div.
					$('submeny').adopt(html);
				},
				//Our request will most likely succeed, but just in case, we'll add an
				//onFailure method which will let the user know what happened.
				onFailure: function() {
					$('submeny').set('text', '');
		}
	});

req.send();
}



function CloseSub(){
			
		setTimeout("$('subs').setStyle('display','none');", "500");
}

		function CollectData(id){
			if(id == 1){
			var data = "<br /><p style='margin-left:90%;' onclick='CloseSub();'>stäng</p><h2 class='ontop'>Shopping</h2><ul>							<li><a href='#'>Ateljé Orrling Guld</a></li><li>Bang & Olufsen Center </li><li>Bellis Blomsterhandel </li><li>Intersport</li><li>Berggrens Guld</li><li>Boutique Looking</li><li>Brothers</li>						</ul>							<ul>							<li>Bogdan Grill</li><li>Konfektasken</li><li>Sister</li><li>Tobaksboden</li><li>Morris</li>						</ul>	<ul>							<li>Lindex</li><li>Dressman</li><li>Brothers</li><li>Intersport</li><li>Åhlens</li><li>Army Store</li><li>City huset</li>						</ul>	<ul>							<li>Bogdan Grill</li><li>Konfektasken</li><li>Sister</li><li>Tobaksboden</li><li>Morris</li><li>Den Gröna kon</li>						</ul>";
			$('subs').innerHTML = data;
			}else{
				var data = "<br /><p style='margin-left:90%;' onclick='CloseSub();'>stäng</p><h2 class='ontop'>Rest</h2><ul>							<li><a href='#'>Lindex</a></li><li>Dressman</li><li>Brothers</li><li>Intersport</li><li>Åhlens</li><li>Army Store</li><li>City huset</li>						</ul>";
			$('subs').innerHTML = data;


			}

		}
