var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18697678-4']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

$(document).ready(function() {	

	var diff = Math.abs($('ul.menu').get(0).offsetLeft - $('li a.yayin').get(0).offsetLeft) - (Math.abs($('#yayin').width()-$('li a.yayin').width())/2);
	$('#yayin').css('margin-left',diff);
	
	$(".sub > li").hide();

	$(".muze").click(function() {
		$(".sub > li").hide();
		$("#museum").fadeIn("fast");
		return false;
	});	
	
	$(".sergi").click(function() {
		$(".sub > li").hide();
		$("#exhibitions").fadeIn("fast");
		return false;
	});
	
	$(".etkinlik").click(function() {
		$(".sub > li").hide();
		$("#events").fadeIn("fast");
		return false;
	});	

	$(".egitim").click(function() {
		$(".sub > li").hide();
		$("#education").fadeIn("fast");
		return false;
	});	

	$(".halic").click(function() {
		$(".sub > li").hide();
		$("#halic").fadeIn("fast");
		return false;
	});
	
	$(".yayin").click(function() {
		$(".sub > li").hide();
		$("#yayin").fadeIn("fast");
		return false;
	});
	
	$('.changeFont').cycleFontSize({maxFontSize:"24px",increaseEle: ".grid_11 p"}); 

	dublib.menuHighligher('ul.menu','active');

	$('ul.gallery li a[rel="content-gallery"]').fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">' + title + '</span>';
		}
	});
	
	$('a.fancybox').fancybox({
		'showTitles': false
	});
	
	$('a.inline_fancybox').fancybox({
		width: 920,
		height: 600,
		autoScale: false,
		autoDimensions: false
	});
	
	Cufon.replace('.content .page h1,.content .publication h1,#legal_notices h1,#legal_notices h2');
	
	$(".print").click( function() {
      $('.toPrint').jqprint();
      return false;
  });
});

function pad(number, length){
   var str = "" + number;
   while(str.length<length){
      str = '0'+str;
   }
   return str;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return {x:curleft,y:curtop};
	}
}

function getSelectorFromDate(date){
	return 'td.'+date;
}

function showTooltip(date){
	clearTimeout(tooltip_delay);
	cell = $(getSelectorFromDate(date)).get(0);
	info = $('div.info.'+date);
	if(info.length != 0){
		pos = findPos(cell);
		var tooltip = $('#tooltip');
		var tooltip_content = $('#tooltip_content');
		tooltip_content.html(info.html());
		tooltip.css({
			"position" : "absolute",
			"left"     : pos.x - $('#tooltip').width(),
			"top"      : pos.y-12
		});
		tooltip.show();
		tooltip.css({
			"left"     : pos.x - $('#tooltip').width(),
			"top"      : pos.y-12
		});
		tooltip.hide();
		tooltip.fadeIn();
	}
}
