var initStory = function(){
	$('.col p:first, #page_konsten-att-komma-hem-varje-dag .slide:first, #page_konsten-att-komma-hem-varje-dag .slide:first, #page_cesar-och-kvinnorna .slide:first, #page_the-art-of-coming-home-every-day .slide:first, #page_the-art-of-coming-home-every-day .slide:first, #page_cesar-and-the-women .slide:first')
		.each(function(){
			$(this).addClass('first');
		});
		
		
	$('.stories .slide .content').find('.col:last')
		.each(function(){
			$(this)
				.addClass('last')
				.css({
					'border-right'	: 'none',
					'margin-right'	: '0',
					'padding-right'	: '0'
				});
		});
	
	$('.stories .col').find('.col:last')
		.each(function(){
			$(this)
				.addClass('last')
				.css({
					'border-right'	: 'none',
					'margin-right'	: '0',
					'padding-right'	: '0'
				});			
		})
}

var clearAllTimeouts = function(){
  for(key in timeOuts ){
    clearTimeout(timeOuts[key]);
  }
}

var getAlias = function(){
	return getAliasFromHREF(window.location.href);
}

var getAliasFromHREF = function(href){
	var pieces = href.split('/');
	var pieces = pieces[pieces.length-1].split('#');
	
	if(pieces[pieces.length-1] == ""){
		return 'intro';
	} else{
		return pieces[pieces.length-1].replace('.html', '');
	}
}

var gMapInit = function(){
	$("#google_map").gMap({
		latitude:               59.32894,
		longitude:              18.06182,
		zoom:                   16,
		markers:                [{
			latitude	: 59.3302295,
			longitude	: 18.053852,
			//html		: '<img src="assets/images/framework/gMap-1.jpg" />',
			icon		: {
				image:              "assets/images/framework/marker-1.png",
				shadow:             false,
				iconsize:           [67, 51],
				shadowsize:         false,
				iconanchor:         [19, 40],
				infowindowanchor:   [19, 40]
			}
		},{
			latitude	: 59.3318371,
			longitude	: 18.069620,
			//html		: '<img src="assets/images/framework/gMap-2.jpg" />',
			icon		: {
				image:              "assets/images/framework/marker-2.png",
				shadow:             false,
				iconsize:           [67, 51],
				shadowsize:         false,
				iconanchor:         [19, 40],
				infowindowanchor:   [19, 40]
			}
		}],
		maptype:				G_NORMAL_MAP     
	});		
}

var nav_event = function(hash){
	hash = (hash == '') ? getAlias() : hash;	
	if(navigate_event == 'undefined') {
		if($('a#goto_'+hash).size() > 0) {
			$('a#goto_'+hash).trigger('click');
		}
	}	
	navigate_event = 'undefined';
}

var hideFrame = function(){
	if(is_frame) {
		is_frame = false;
		
		$('.frame.top').animate({
			top:'-'+10+'px'
		}, 400);
		
		$('.frame.right').animate({
			right:'-'+10+'px'
		}, 400);
		
		$('.frame.bottom').animate({
			bottom:'-'+10+'px'
		}, 400);
		
		$('.frame.left').animate({
			left:'-'+10+'px'
		});
		
		// Position room navigation if closed
		if($('#room_navigation').children('.toggle').is(':hidden')){
			$('#room_navigation').animate({
				top		: 10+'px',
				left	: 10+'px'	
			});
		}
	}
}

var showFrame = function(){
	if(!is_frame) {
		is_frame = true;
	
		$('.frame.top').animate({
			top:'0px'
		}, 400);
		
		$('.frame.right').animate({
			right:'0px'
		}, 400);
		
		$('.frame.bottom').animate({
			bottom:'0px'
		}, 400);		
		
		$('.frame.left').animate({
			left:'0px'
		});
		
		// Position room navigation if closed
		if($('#room_navigation').children('.toggle').is(':hidden')){
			$('#room_navigation').animate({
				top		: 10+'px',
				left	: 10+'px'	
			});
		}
	}
}

var intro = function(){
	slideshow.next();
	timeOuts.push(setTimeout("onExitIntro()", 1200));
}

var onExitIntro = function(){
	$('#main_navigation').hide().css('visibility', 'visible').fadeIn(200);
	$('#room_navigation, #main_navigation').find('.lockOverlay').remove();	
	$('#room_navigation').find('.toggler').trigger('click');
	$('#welcomeMessage').fadeIn();
	//$('#room_navigation').css('visibility', 'visible');
	
	$(slideshow.slides[0].element).remove();
	slideshow.slides.splice(0, 1);
	slideshow.currentIndex -= 1;
	slideshow.previousIndex -= 1;
	
	var doMe = "showList('news')";
	
	timeOuts.push(setTimeout(doMe, 800));
	slideshow.Start();
}
