// global variables
var doc = $(document);
var win = $(window);


// global functions
function setArtist () {
	var img = $('#tattooartist');
	var diff = doc.height() - img.height();
		diff = diff + 'px';

	if (doc.height() < img.height()) {
		img.animate({'bottom':diff}, 'fast');
	}
	else{
		img.animate({'bottom':0}, 'fast');
	}
	return true;
}

// document.ready....
$(function(){
	// set artist image when window resize
	setArtist();
	win.bind('resize', function(event){
		setArtist();
	});
	
	
	win.bind('hashchange', function(){
		var hash = location.hash;
		var menu = $('#mainMenu');
		
		
		if($(hash)[0] == undefined && menu.hasClass('shortMenu')){
			
			// hide menu,
			// remove shortMenu class with effect,
			// add largeMenu class with effect
			
			menu.hide('drop', {}, 1000, function(){
				//console.log('hide finished..');
				
				$('li a', menu).removeAttr('style');
				
				menu.removeClass('shortMenu')
					.css('top', '30px')
					.addClass('largeMenu')
					.show('bounce', {}, 500, function(){
						//console.log('show finished..');
					});
			});
		}
		
		
		if ($(hash)[0] != undefined && menu.hasClass('largeMenu')) {
			
			// hide menu,
			// remove largemenu class with effect,
			// add shortMenu class with effect
			
			menu.animate({
				top:'-300px'
			},
			800,  // doğrusu 1000 olacak  ***
			function(){
				setTimeout(function(){
					menu.removeClass('largeMenu');
					$('li', menu)
						.removeAttr('style')
						.parent().css({
							width:'100%'
						});

					var top = $('.content:visible').position().top - 33;
					
					menu.addClass('shortMenu')
						.css('top', top)
						.show('drop', {}, 500, function(){
							/*
							console.log('minimize menu showed..', $(this));
							$.each($(this).children(), function(i, v){
								console.log($(this).position().left, $(this).position().top);
							});
							*/
						});
				}, 400)
			});
		}

		$('#mainMenu a').each(function(){
			var that = $(this);
			that[that.attr('href') === hash ? 'addClass' : 'removeClass']('selected');
		});
		
		$('.content').each(function(){
			var thatId = $(this).attr('id');
			var cleanHash = hash.replace('#', '');
			var item = $('#' + thatId);

			if (thatId == cleanHash) {
				setTimeout(function(){
					item.slideDown(500)
				}, 700);
			}
			else{
				setTimeout(function(){
					item.slideUp(500)
				},0);
			}
		});
		
	});
	win.trigger('hashchange');

	// write menu span's with to jquery data
	$('#mainMenu li a').each(function(i, v){
		width = $(v).width() + 15;
		$(v).data('width', width);
		// console.log($(v).data('width'));
	});
	
	
	$('.shortMenu li a').live('mouseenter', function(){
		var that = $(this);
		var width = that.data('width') + 'px';

		that.animate({
			width: width
		}, 300);
	});
	
	$('.shortMenu li a').live('mouseleave', function(){
		var that = $(this);
		var width = 20 + 'px';
		
		that.animate({
			width: width
		}, 300);
	});
	
	$('.toLeft a, .toRight a').live('click', function(event){
		event.preventDefault();
	});
	
	$('#Hedeflerimiz').changeContent({
		effect:{
			duration:500
		}
	});
	
	$('#SorularCevaplar').changeContent({
		effect:{
			duration:100
		}
	});
});
