/*

	SOFIE VIOLETT PEHRSSON
	2009
	
	www.sofieviolett.se
	
	Author: www.lost-found.se

*/

$(function(){
	// Make the header change depending on time of year and/or time of day
	seasonalHeader();
	
	// Remove the PreNav text and fix the menu
	$(".navNo").remove();
	$("#menu p:first").remove();
	
	// Make columns
	columnMaker();
	
	//Remove "Main" from Main title
	if ($("#content").hasClass("Main")){
		$("#content h1").remove();
		$("#content .container").html('<img src="/ndxz-studio/site/svp/img/monogram.gif" />');
	}
	
	//FANCYBOX
	$("a#zoomimg").fancybox();
	
	// Make the menu stop at a certain width
	$(window).resize(function(){
		if ($(window).width() < 1082) {
			$("#menu").css({'right':'', 'left':'750px'});
		} else {
			$("#menu").css({'right':'100px', 'left':''});
		}
	});
	
	
	// AJAXify the nav-bar
	$("#menu li a").each(function(e){
		var url = 	$(this).attr("href");
		urlHash = url.replace(new RegExp(/^http:\/\/sofieviolett.se/i),"");		
		$(this).attr({"href": urlHash})
	});
	
	
	$("#menu li a").click(function(e){
		e.preventDefault();

		//define the target and get content then load it to container
		var url = $(this).attr("href");
		var targetUrl = url + " #content";
		setTitle($(this).html());
		$("#wrap").load(targetUrl, columnMaker);
	//	urlHash = url.replace(new RegExp(/^http:\/\/sofieviolett.se/i),"");
		window.location.hash = url;
		$("#loader").fadeIn();
	});
	
	// Understand hash urls
	if(window.location.hash) {}
	else {
		theAdd = location.href;
		theAdd = theAdd.replace("http://sofieviolett.se/", "");
		window.location = "/#/" + theAdd;
	}
	var current_hash = false;
    setInterval(function() {
        if(window.location.hash != current_hash) {
        	
            current_hash = window.location.hash;
            $("#wrap").load(current_hash.substring(1)+" #content", function(){
            pageTracker._trackPageview(current_hash.substring(1));
            	columnMaker();
            	setTitle($("#content h1").html());
				
            });
            
        }        
    }, 100);    
    
    // seasonChooser   function
	$(".sc-1").click(function(){
		$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/winter.jpg')"});
	});
	$(".sc-2").click(function(){
		$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/spring.jpg')"});
	});
	$(".sc-3").click(function(){
		$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/summer.jpg')"});
	});
	$(".sc-4").click(function(){
		$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/autumn.jpg')"});
	});
	
});

function setTitle(titleToSet) {
	if (titleToSet == null) {
		document.title = "Sofie Violett Pehrsson";
	} else {
		document.title = titleToSet + " : Sofie Violett Pehrsson";
	}
}

function columnMaker() {

		if ($("#content").hasClass("section-1")) {} else {
			$("#content p:eq(0)").addClass("col1");
			$("#content p:eq(1)").addClass("col2");
			$(".col2").height($(".col1").height()+10);
		}
		
		$('#s1').cycle({
			fx:'fade', 
			speed:'2000', 
			timeout: 0, 
			next:'#next, .img-bot', prev:'#prev'
		});
		$("#loader").fadeOut();
		
	if ($("#content").hasClass("Main")){
		$("#content h1").remove();
		$("#content .container").html('<img src="/ndxz-studio/site/svp/img/monogram.gif" />');
	}
	//FANCYBOX
	$("a#zoomimg").fancybox();
}

function seasonalHeader() {
	var date = new Date()
	var month = date.getMonth()+1;
	var hour = date.getHours();
	if (hour < 5 | hour > 22) {
		$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/night.jpg')"});
	} else {
		switch(month) {
		 case 12:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/winter.jpg')"});
			break;
		 case 1:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/winter.jpg')"});
			break;
		 case 2:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/winter.jpg')"});
			break;
		 case 3:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/spring.jpg')"});
			break;
		 case 4:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/spring.jpg')"});
			break;
		 case 5:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/spring.jpg')"});
			break;
		 case 6:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/summer.jpg')"});
			break;
		 case 7:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/summer.jpg')"});
			break;
		 case 8:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/summer.jpg')"});
			break;
		 case 9:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/autumn.jpg')"});
			break;
		 case 10:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/autumn.jpg')"});
			break;
		 case 11:
			$("#tear").css({"background":"url('http://sofieviolett.se/ndxz-studio/site/svp/img/seasons/autumn.jpg')"});
			break;
			
		}
	}
	
}