$(document).ready(function(){
	
	Cufon.replace('#menu li a', {hover:true,hoverables:{a:true},fontFamily: 'NudistaMedium'});
	Cufon.replace('.mainText p', {fontFamily: 'NudistaMedium'});
	Cufon.replace('.mainQuotation .quotation', {fontFamily: 'NudistaMedium'});
	Cufon.replace('.mainQuotation .owner', {fontFamily: 'NudistaMedium'});
	Cufon.replace('.mainQuotation .quotation', {fontFamily: 'NudistaMedium'});
	Cufon.replace('#subNavigation .title', {fontFamily: 'NudistaSemiBold'});
	Cufon.replace('#subNavigation .text', {fontFamily: 'NudistaMedium'});
	
	
	Cufon.replace('.heading .title', {fontFamily: 'NudistaSemiBold'});
	Cufon.replace('.heading .text', {fontFamily: 'NudistaMedium'});
	Cufon.replace('.heading .message', {fontFamily: 'NudistaMedium'});
	Cufon.replace('.contact dl', {fontFamily: 'NudistaMedium'});
	Cufon.replace('.contact p', {fontFamily: 'NudistaMedium'});
	Cufon.replace('.cuf01', {fontFamily: 'NudistaMedium'});
	Cufon.replace('.box.comment', {fontFamily: 'NudistaMedium'});	
	
	
	Cufon.CSS.ready(function(){
		
		
		
		$('#menu a').hover(
			function () {
				$(this).next().addClass('hover');
			},
			function () {
				$(this).next().removeClass('hover');
			}
		);
		
		
		
		
		$('.slideshowItem:first').addClass('active');
		$('#subNavigation .title').html($('#slideshow .active').attr('title') + ":");
		$('#subNavigation .text').html($('#slideshow .active').attr('text'));
		Cufon.replace('#subNavigation .title', {fontFamily: 'NudistaSemiBold'});
		Cufon.replace('#subNavigation .text', {fontFamily: 'NudistaMedium'});
		
		$('.slideshowItem').each(function(index){
			if (index != 0){
				$(this).children('img').attr('width', 300);
				$(this).addClass('passive');
			}
		});
		
		$('.slideshowItem').hover(
			function () {
				$(this).addClass('hover');
			},
			function () {
				$(this).removeClass('hover');
			}
		);
		
		$('.slideshowItem').click(function(e){
			window.location = $(this).attr('url');
			/*
			e.preventDefault();
			if (!$(this).hasClass('active')){
				if (Number($('#slideshow').attr('shows')) == (Number($('#slideshow').attr('count')) - 1)){
					prevSlideshowItem();
				}
				else{
					nextSlideshowItem();
				}
			}
			*/
		});
		
		function nextSlideshowItem(){
			if (Number($('#slideshow').attr('shows')) < (Number($('#slideshow').attr('count')) - 1)){
				$('#slideshow').attr('shows', Number($('#slideshow').attr('shows')) + 1);
				changeSlideshow();
			}
		}
		
		function prevSlideshowItem(){
			if (Number($('#slideshow').attr('shows')) > 0){
				$('#slideshow').attr('shows', Number($('#slideshow').attr('shows')) - 1);
				changeSlideshow();
			}
		}
		
		function changeSlideshow(){
			if (Number($('#slideshow').attr('shows')) != (Number($('#slideshow').attr('count')) - 1)){
				$('#slideshowInner').animate({marginLeft: - $('#slideshow').attr('shows') * 320}, 600);
			}
			//old active
			if ($('#slideshow .active').hasClass('image')){
				$('#slideshow .active').children('img').animate({width: 300}, 600);
			}
			if ($('#slideshow .active').hasClass('vimeo')){
				$('#slideshow .active').children('iframe').animate({width: 300, height: 134}, 600);
			}
			$('#slideshow .active').animate({marginTop: 0}, 600, function(){
				$('#slideshow .active').addClass('passive');
				$('#slideshow .active').removeClass('active');
			});
			
			//new active
			if ($('.slideshowItem').eq($('#slideshow').attr('shows')).hasClass('image')){
				$('.slideshowItem').eq($('#slideshow').attr('shows')).children('img').animate({width: 300}, 600);
			}
			if ($('.slideshowItem').eq($('#slideshow').attr('shows')).hasClass('vimeo')){
				$('.slideshowItem').eq($('#slideshow').attr('shows')).children('iframe').animate({width: 300, height: 280}, 600);
			}
			
			$('.slideshowItem').eq($('#slideshow').attr('shows')).animate({marginTop: 0}, 600, function(){
				$('.slideshowItem').eq($('#slideshow').attr('shows')).removeClass('passive');
				$('.slideshowItem').eq($('#slideshow').attr('shows')).addClass('active');
			});
			$('#subNavigation .title').html($('#slideshow .active').attr('title') + ":");
			$('#subNavigation .text').html($('#slideshow .active').attr('text'));
			Cufon.replace('#subNavigation .title', {fontFamily: 'NudistaSemiBold'});
			Cufon.replace('#subNavigation .text', {fontFamily: 'NudistaMedium'});
		}
		
		
		
		$('#slideshow #rightArrow a').click(function(e){
			e.preventDefault();
			nextSlideshowItem();
		});
		
		$('#slideshow #leftArrow a').click(function(e){
			e.preventDefault();
			prevSlideshowItem();
		});
		
		
		$('#works a').hover(
			function () {
				$(this).children('.work').addClass('hover');
			},
			function () {
				$(this).children('.work').removeClass('hover');
			}
		);
		
		$('#subNavigation #leftTextLink').hover(
			function () {
				$('#subNavigation #leftArrow a').css('marginLeft', -38);
			},
			function () {
				$('#subNavigation #leftArrow a').css('marginLeft', 0);
			}
		);
		
		$('#subNavigation #leftTextLink').click(function(e){
			$('#subNavigation #leftArrow a').trigger('click');
		});
		
		$('#subNavigation #rightTextLink').hover(
			function () {
				$('#subNavigation #rightArrow a').css('marginLeft', -38);
			},
			function () {
				$('#subNavigation #rightArrow a').css('marginLeft', 0);
			}
		);
		
		var box=$('.pageBox');
		
		$('#subNavigation #rightTextLink').click(function(e){
			$('#subNavigation #rightArrow a').trigger('click');
		});
		
		$('.subNavigationForPage #rightArrow a').click(function(e){
			e.preventDefault();
			
			nextPage(box);
		});
		
		$('.subNavigationForPage #leftArrow a').click(function(e){
			e.preventDefault();
			
			prevPage(box);
		});
		
		$('.subNavigationForPage .arrow a').hover(
			function () {
				$(this).css('marginLeft', -38);
			},
			function () {
				$(this).css('marginLeft', 0);
			}
		);
		
		$('.heading .rightArrow a').hover(
			function () {
				$(this).css('marginLeft', -32);
			},
			function () {
				$(this).css('marginLeft', 0);
			}
		);
		
		$('.heading .textLink').hover(
			function () {
				$('.heading .rightArrow a').css('marginLeft', -32);
			},
			function () {
				$('.heading .rightArrow a').css('marginLeft', 0);
			}
		);		
		
		$('.heading .textLink').click(function(e){
			$('.heading .rightArrow a').trigger('click');
		});
		
		$('.heading .rightArrow a').click(function(e){
			e.preventDefault();
			window.location = $(this).attr('href');
		});
		
		$('.subNavigationForWorkDetail #rightArrow a').click(function(e){
			e.preventDefault();
			window.location = $(this).attr('href');
		});
		
		$('.subNavigationForWorkDetail #leftArrow a').click(function(e){
			e.preventDefault();
			window.location = $(this).attr('href');
		});
						
		function nextPage(box){
			if (Number(box.attr('current')) < (Number(box.attr('total')) - 1)){
				box.attr('current', Number(box.attr('current')) + 1);
				changePage(box);
			}
		}
		
		function prevPage(box){
			if (Number(box.attr('current')) > 0){
				box.attr('current', Number(box.attr('current')) - 1);
				changePage(box);
			}
		}
		
		function changePage(box){			
			var boxInner='';
			if(box.attr('id')=='works') boxInner=$('#worksInner');
			else if(box.attr('id')=='page') boxInner=$('#pageInner');
			
			
			if(Number(box.attr('current'))==0 && $('.subNavigationForWorkDetail').length==0) $('#leftArrow,#leftTextLink').hide();
			else $('#leftArrow,#leftTextLink').show();

			if(Number(box.attr('current'))==Number(box.attr('total')) - 1) $('#rightArrow,#rightTextLink').hide();
			else $('#rightArrow,#rightTextLink').show();
			
			
			boxInner.animate({marginLeft: - box.attr('current') * 780}, 1000);
		}
		
		$('#sitemap').css('top',-($(this).height()+40)).hide();

		$('.sm').click(function(e){e.preventDefault();})	
		$('.site-map')		
		.hover(function(){
			$('#sitemap').stop().show().animate({top:30},500).addClass('visible');
			$('#header ul li:not(".site-map")').css('opacity',0.4);
			$('#sitemap li').css('opacity',1);
			$(this).addClass('active');
		},
		function(){
			$('#sitemap').stop().animate({top:(-($('#sitemap').height()+40))}, 500, function(){$('#sitemap').hide()});
			$('#header ul li').css('opacity',1);
			$(this).removeClass('active');
		})
		
		$('#work .photos').cycle({
			fx: 		'fade', 
		    speed: 		500,
			timeout: 	4000,
			pager: 		'#photoNav',
			prev: 		'#photoPrev',
			next: 		'#photoNext',
			after: 		function() {
							$('#photoCaption').html(this.alt);
						}
		});
		
		
		$(window).resize(function() {
			windowResized();
		});
		//alert($('#slideshow').position().top);
		
		windowResized();
	});
	
});


function windowResized(){
	
	if ($('#slideshow').length > 0){
		$('#slideshow').css('paddingTop', Math.max($(window).height() - 623, 20));
	}
	
	if ($('#content .subNavigationForPage').length > 0){
		//$('#content .subNavigationForPage').css('marginTop', Math.max($(window).height() - 545, 20));
	}
	
	if ($('#content .subNavigationForWorkDetail').length > 0){
		var workHeight=$('#work').height();
		//$('#content .subNavigationForWorkDetail').css('marginTop', Math.max($(window).height() - workHeight-40-85, 20));
	}
	
	if($('.iletisim').length>0)
	{
		$('#mapBox').css('paddingTop', Math.max($(window).height() - 634, 20));
	}
	
}



