$(function() {
	$("#clickme").css("opacity", 0);
	$("#clickme").animate({
		opacity: 0.7
		}, 
		function(){
			
		}
	);
	$("#wrapper").fadeIn(1500, function(){
		Viktor.view.init();
	});
	//$("#footer").animate({ width: "100%"}, 1500);
    $('#pics a').lightBox();
		
      Viktor.view = new Viktor.View();
      Viktor.service = new Viktor.Service();
    	Viktor.NewsLoader.view = new Viktor.NewsLoader.View();
    	Viktor.NewsLoader.model = new Viktor.NewsLoader.Model();
    	//Viktor.Tumblr.view = new Viktor.Tumblr.View();
    	//Viktor.Tumblr.model = new Viktor.Tumblr.Model();

    	Viktor.service.sendEvent("LOAD_FEED", "news");
    	Viktor.service.sendEvent("LOAD_FEED", "press");
    	Viktor.service.sendEvent("LOAD_PAGE", "contact");
    	Viktor.service.sendEvent("LOAD_PAGE", "cv");
//			Viktor.service.sendEvent("LOAD_FEED", "texts");
    	
    	$("#pics a").bind("click", function(){
    		//$.history.load("work/" + $(this).attr("rel"));
    	});
    	
    	$.history.init(function(url){
    		//alert(url);
    		Viktor.view.showContent(url);
    	});
    	
    	
    	
        /*** events move to controller or such place ***/
    	$('#menu_cv a').click(function () {
        	this.blur();
        	$.history.load("cv");
        	return false;
    	});
       $('#menu_work a').click(function () {
        	this.blur();
        	$.history.load("work");
        	return false;
    	});
    	$('#menu_news a').click(function () {
    		this.blur();
    		$.history.load("news");
    		return false;
    	});
    	$('#menu_press a').click(function () {
    		this.blur();
    		$.history.load("press");
    		return false;
    	});
    	$('#menu_contact a').click(function () {
    		this.blur();
    		$.history.load("contact");
    		return false;
    	});
    	$('#menu_texts a').click(function () {
    		this.blur();
    		$.history.load("texts");
    		return false;
    	});
    	$('#menu_blog a').click(function () {
    		this.blur();
    		$.history.load("blog");
    		return false;
    	});

		$('#clickme').click(function() {
			Viktor.view.showMenu();
			return false;
		});	
    	$('#clickme h1').css({opacity: 0}).animate({opacity:1}, { duration:6000});
    	
    	//hmmm replace below with ordanary css hover if no transistion is needed
    	$('#clickme h1').hover(
    	    function(){
    	         $(this).css({color:'#CDCDCD'}); //mouseover
    	    },
    	    function(){
    	         $(this).css({color:'#a0a0a0'}); // mouseout
    	    }
    	);
});

//global variables
Viktor = {};
Viktor.SITE_URL = "http://"+window.location.host+"/wp-index.php";
Viktor.CONTACT_URL = "http://"+window.location.host+"/wp-index.php?page_id=3&json=1";
Viktor.PRESS_URL = "http://"+window.location.host+"/wp-index.php?page_id=5&json=1";
Viktor.CV = "http://"+window.location.host+"/wp-index.php?page_id=17&json=1";
Viktor.TEXTS = "http://"+window.location.host+"/viktorrosdahl.se/wp-index.php?cat=6&json=1";
Viktor.SWE_NEWS_CAT = "3";
Viktor.PRESS_CAT = "4";
Viktor.NEWS_CONTENT_HOLDER = "#news"
Viktor.NEWS_OUTER_HOLDER = "#new_outer_holder";
Viktor.PRESS_HOLDER = "#press_outer_holder";
Viktor.CONTACT_HOLDER = "#contact_outer_holder";
Viktor.loaded = 'blog';
Viktor.what_to_load = -1;
Viktor.work_to_show = -1;
Viktor.show_on_start = -1;


/***
 * View class that controlls the html
 */
Viktor.View = function(){
	//construktor
	//this.init();
}
Viktor.View.prototype = {
	init:function(){
		if(window.location.hash.length > 1){
			//this.showContent(window.location.hash.substring(1));
			if(window.location.hash != "#work")
			{
				Viktor.show_on_start = window.location.hash.substring(1); 
			}
			//this.showMenu();
		}
	},
	showContent : function(toShow){
		var self = this;
		//set what to load
		if(toShow == ''){
			toShow = 'blog';
		}
		Viktor.what_to_load = toShow;
		if(toShow.indexOf("/") > 0)
		{
			Viktor.what_to_load = toShow.substring(0, toShow.indexOf("/"));
			toShow = Viktor.what_to_load;
			if(Viktor.what_to_load == "work")
			{
				Viktor.work_to_show = toShow.substring(toShow.indexOf("/")+1, toShow.length);
			}
			else
			{
				Viktor.work_to_show = -1;
			}
		}
		
		//if the same link is clicked as show = do nothing
		if(Viktor.loaded != toShow)
		{
			// else hide and show
			if(Viktor.loaded != -1){
				$("#" + Viktor.loaded + "_outer_holder").slideToggle("fast", function(){
					self._animateDownCurrent();
				});
			}
			else{
				this._animateDownCurrent();
			}
		}
	},
	/***
	 * Internal function that animates down the content to show
	 */
	_animateDownCurrent : function(){
		$("#menu .menu_current").removeClass("menu_current");
		$("#menu_" + Viktor.what_to_load).addClass("menu_current");
		$("#" + Viktor.what_to_load + "_outer_holder").slideToggle("medium", function(){
			Viktor.loaded = Viktor.what_to_load;
		});
	},
	showMenu : function(){
		
		$('#menu').animate(
		{
		  	'left' : '0' 
		}, {
			     duration: 1500,
			     easing: 'easeOutCubic'
		});
	}
}

Viktor.Model = function(){
	// model construktor
}
Viktor.Model.prototype = function(){
	
}

