/* =============================================================================================== 
	Main JavaScript Effects for arefjdey.com 
	Version 1.0
	Copyright (c) 2009 Matthias Kretschmann | krema@jpberlin.de | http://matthiaskretschmann.com
	Created for Aref JDEY | http://arefjdey.com
================================================================================================== */

$(function () {

	$('#lightspot').css({'opacity' : '0'});
	$('#scroll').css({'height' : '370px', 'overflow' : 'hidden' });
	$('#about-en').css({'opacity' : '0.6' });
	//Target IE6 and below for this; so bad but needed here
		if ($.browser.msie && $.browser.version <= 6 ) $('#about-en').css({'opacity' : '' });
	$('#contact').css({'margin-right' : '110px' });
	
	//About text switch
	$('#about-en h3').click(function () {
		$('#about-fr').animate({ opacity: "toggle", height: "toggle" }, 500);
		$('#about-en').animate({ opacity: 1	}, 500);
		//Target IE6 and below for this; so bad but needed here
		if ($.browser.msie && $.browser.version <= 6 ) $('#about-en').animate({'opacity' : '' });
    	$('#about-en h3').toggleClass('active');
	});
	    	
	//start the tabbing, sliding fun
	var $panels = $('#about-content, #networks');
	var $container = $('#scrollContainer');
	var horizontal = true;
	if (horizontal) {
	  $panels.css({
	    'float' : 'left',
	    'position' : 'relative'
	  });
	  $container.css({'width' : '900px' });
	  	
	  	//Target IE6 and below for this; so bad but needed here
		if ($.browser.msie && $.browser.version <= 6 ) $container.css({'width' : '800px' });
	}
	var $scroll = $('#scroll').css('overflow', 'hidden');
	$('li.networks-tab a').click(function() {		
			$(this).addClass('current');
			$('li.about-tab a').removeClass('current');
	});
	$('li.about-tab a').click(function() {
			$(this).addClass('current');
			$('li.networks-tab a').removeClass('current');
	});
	$('a#photo-clip, #header h1').click(function() {
		$('li.networks-tab a').removeClass('current');
		$('li.about-tab a').addClass('current');	
	});
	
	function trigger(data) {
	  var el = $('#navigation').find('a[href$="' + data.id + '"]').get(0);
	}
	if (window.location.hash) {
	  trigger({ id : window.location.hash.substr(1) });
	} else {
	  $('ul#navigation a:first').click();
	}
	var scrollOptions = {
	  target: $scroll,
	  items: $panels,
	  navigation: '#navigation a',
	  axis: 'xy',
	  onAfter: trigger, 
	  duration: 800
	};
	$('#scroll').serialScroll(scrollOptions);
	$.localScroll(scrollOptions);
	scrollOptions.duration = 1;
	$.localScroll.hash(scrollOptions);
    
    //website and download links nudging
	$('#networks a').hover(function () {
    	$(this).stop().animate({marginLeft: '6px'}, 300 );
		    }, function() {
		      $(this).stop().animate({marginLeft: '0px'}, 300 );
	});
	
	//download link nudging
	$('a.download span').hover(function () {
    	$(this).stop().animate({marginLeft: '5px'}, 300 );
		    }, function() {
		      $(this).stop().animate({marginLeft: '0px'}, 300 );
	});

});//don't delete me or the DOM will collaps

//Finally switch the light on
$(window).load(function() {
	$('#lightspot').animate ({ opacity: 1}, 700);
});

//try to hide the URL bar on iPhone
if (navigator.userAgent.indexOf('iPhone') != -1) {
        addEventListener("load", function() {
                setTimeout(hideURLbar, 0);
        }, false);
}
function hideURLbar() {
        window.scrollTo(0, 1);
}
