$(document).ready(function(){
	
	
	Cufon.replace('#secondary-navigation a', {hover:true,hoverables:{a:true},fontFamily: 'EffraBold'});
	Cufon.replace('#newsletter-registration label', {fontFamily: 'EffraBold'});
	
	Cufon.replace('#primary-navigation a', {hover:true,hoverables:{a:true},fontFamily: 'EffraBold'});
	Cufon.replace('#tertiary-navigation a', {hover:true,hoverables:{a:true},fontFamily: 'EffraBold'});
	Cufon.replace('#content .title', {fontFamily: 'MatrixBoldItalic'});
	Cufon.replace('#content .date', {fontFamily: 'MatrixBoldItalic'});
	Cufon.replace('#content .portions', {fontFamily: 'MatrixItalic'});
	Cufon.replace('#content .highlight', {fontFamily: 'MatrixItalic'});
	
	Cufon.replace('#language', {hover:true,hoverables:{a:true},fontFamily: 'EffraMedium'});
	
	Cufon.replace('.subNavigation .level1', {fontFamily: 'EffraBold'});
	Cufon.replace('.subNavigation .levelx a', {hover:true,hoverables:{a:true},fontFamily: 'EffraBold'});
	Cufon.replace('.subNavigation .level2 a', {hover:true,hoverables:{a:true},fontFamily: 'EffraMedium'});
	Cufon.replace(".inactive", {fontFamily: 'EffraBold'});
	Cufon.replace('#content label', {fontFamily: 'EffraBold'});
	
	Cufon.replace('.product-link .detail', {fontFamily: 'MatrixBoldItalic'});
	
	Cufon.replace('#spots .column .spot .header', {fontFamily: 'EffraBold'});
	
	/* SHOPPING */
	Cufon.replace('#spots .column .shoppingCart .register a', {hover:true,hoverables:{a:true},fontFamily: 'EffraBold'});
	Cufon.replace('#spots .column .shoppingCart .info', {fontFamily: 'EffraBold'});
	
	/* SHOPPING */
	
	Cufon.replace('#product-detail #productPhotoNumbers .number a', {hover:true,hoverables:{a:true},fontFamily: 'EffraMedium'});
	Cufon.replace('#product-detail #corporate-sale a', {hover:true,hoverables:{a:true},fontFamily: 'EffraBold'});
	
	Cufon.replace('#product-detail .designers', {hover:true,hoverables:{a:true},fontFamily: 'MatrixItalic'});

	Cufon.replace('#minimap #mHeader', {fontFamily: 'EffraBold'});
	Cufon.replace('#minimap #mFooter .zTitle', {fontFamily: 'EffraBold'});
	
	Cufon.replace('.three-column .submenu a', {hover:true,hoverables:{a:true},fontFamily: 'EffraBold'});
	Cufon.replace('.two-column .submenu a', {hover:true,hoverables:{a:true},fontFamily: 'EffraBold'});
	
	Cufon.replace('.three-column .thumb .inner .left', {fontFamily: 'MatrixItalic'});
	Cufon.replace('.three-column .thumb .inner .right', {fontFamily: 'MatrixItalic'});
	
	Cufon.replace('#news-detail #productPhotoNumbers .number a', {hover:true,hoverables:{a:true},fontFamily: 'EffraMedium'});
	
	Cufon.replace('#carouselController', {hover:true,hoverables:{a:true},fontFamily: 'EffraMedium'});
	
	
	Cufon.replace('#related-carousel .related .header', {fontFamily: 'EffraBold'});
	
	Cufon.replace('#related-carousel .related .right', {fontFamily: 'MatrixBoldItalic'});
	
	
	Cufon.replace('#content .subtitle', {fontFamily: 'EffraBold'});
	Cufon.replace('#content .subtitle2', {fontFamily: 'EffraMedium'});
	
	
	
	
	
	$('#facebookCon .fb').click(function(){
		window.open("http://www.facebook.com/kahvedunyasi");
		//window.location = "http://www.facebook.com/kahvedunyasi";
	});
	$('#twitterCon').click(function(){
		window.open("http://twitter.com/kahvedunyasicom");
		//window.location = "http://twitter.com/kahvedunyasicom";
	});
	$('#newsletter-registration-email').focus(
		function() {  
			if (this.value == this.defaultValue){  
				this.value = '';  
			}
			if (this.value == "Email adresinizi kontrol ediniz."){  
				this.value = '';  
			}
			if (this.value == "Email adresiniz kaydedilmiştir."){  
				this.value = '';  
			}
			if (this.value == "Check your e-mail address."){  
				this.value = '';  
			}
			if (this.value == "Thanks"){  
				this.value = '';  
			}
		}
	);
	
	$('#newsletter-registration-email').blur(
		function() {  
			if ($.trim(this.value) == ''){
				this.value = (this.defaultValue ? this.defaultValue : '');  
			}
		}
	);
	
	$('#newsletter-registration-email-iletisim').focus(
		function() {  
			if (this.value == this.defaultValue){  
				this.value = '';  
			}
			if (this.value == "Email adresinizi kontrol ediniz."){  
				this.value = '';  
			}
			if (this.value == "Email adresiniz kaydedilmiştir."){  
				this.value = '';  
			}
			if (this.value == "Check your e-mail address."){  
				this.value = '';  
			}
			if (this.value == "Thanks"){  
				this.value = '';  
			}
		}
	);
	
	$('#newsletter-registration-email-iletisim').blur(
		function() {  
			if ($.trim(this.value) == ''){
				this.value = (this.defaultValue ? this.defaultValue : '');  
			}
		}
	);

	$('#contact-email').focus(
		function() {  
			if (this.value == this.defaultValue){  
				this.value = '';  
			}
		}
	);

	$('#contact-email').blur(
		function() {  
			if ($.trim(this.value) == ''){
				this.value = (this.defaultValue ? this.defaultValue : '');  
			}
		}
	);
	
	
	
	$('#primary-navigation a').hover(
		function () {
			if (!$(this).parent().hasClass('selected')){
				$(this).parent().children('.bg').css('display', 'block');
			}
		},
		function () {
			if (!$(this).parent().hasClass('selected')){
				$(this).parent().children('.bg').css('display', 'none');
			}
		}
	);
	
	$('#primary-navigation a').click(
		function (e) {
			if (!$(this).parent().hasClass('selected')){
				if ($(this).attr('href') == '#'){
					e.preventDefault();
					
					$oldSubNav = '';
					if ($('#subNavigationHolder #subnav-' + $(this).parent().parent().children('.selected').children('a').attr('subnav')).length > 0){
						$oldSubNav = $('#subNavigationHolder #subnav-' + $(this).parent().parent().children('.selected').children('a').attr('subnav'));
					}
					
					$(this).parent().parent().children('.selected').children('.bg').css('display', 'none');
					$(this).parent().parent().children('.selected').removeClass('selected');
					Cufon.replace('#primary-navigation a', {hover:true,hoverables:{a:true},fontFamily: 'EffraBold'});
					
					if ($('#subNavigationHolder').css('height') == '0px'){
						$('#subNavigationHolder #subnav-' + $(this).attr('subnav')).css('display', 'block');
						$('#subNavigationHolder').animate({'height': $('#subNavigationHolder #subnav-' + $(this).attr('subnav')).outerHeight(true)}, 500);
					}
					else{
						$newSubNav = $('#subNavigationHolder #subnav-' + $(this).attr('subnav'));
						$('#subNavigationHolder').animate({'height': 0}, 250, function(){$oldSubNav.css('display', 'none'); $newSubNav.css('display', 'block');});
						$('#subNavigationHolder').animate({'height': $('#subNavigationHolder #subnav-' + $(this).attr('subnav')).outerHeight(true)}, 500);
					}
					
					$(this).parent().addClass('selected');
				}
			}
		}
	);
	
	$('.ukMenu').click(
		function (e) {
			e.preventDefault();
			if (!$(this).hasClass('selected')){
				$.post("/en/changeMonu", { 'monu' : 'monu-uk'}, 
				function(data){
					$('#primary-navigation li:nth-child(4)').children('a').attr('subnav', 'monu-uk');
					$location = location.href;
					$reload = 0;
					if ($location.indexOf('menu') > 0){
						$reload = 1;
					}
					$oldSubNav = $('#subNavigationHolder #subnav-monu');
					$newSubNav = $('#subNavigationHolder #subnav-monu-uk');
					$('#subNavigationHolder').animate({'height': 0}, 250, function(){$oldSubNav.css('display', 'none'); $newSubNav.css('display', 'block');});
					$('#subNavigationHolder').animate({'height': $('#subNavigationHolder #subnav-monu-uk').outerHeight(true)}, 500, function(){if ($reload == 1){ location.reload(true); }});
				},"json");
			}
		}
	);
	
	$('.globalMenu').click(
		function (e) {
			e.preventDefault();
			if (!$(this).hasClass('selected')){
				$.post("/en/changeMonu", { 'monu' : 'monu'}, 
				function(data){
					$('#primary-navigation li:nth-child(4)').children('a').attr('subnav', 'monu');
					$location = location.href;
					$reload = 0;
					if ($location.indexOf('menu') > 0){
						$reload = 1;
					}
					$oldSubNav = $('#subNavigationHolder #subnav-monu-uk');
					$newSubNav = $('#subNavigationHolder #subnav-monu');
					$('#subNavigationHolder').animate({'height': 0}, 250, function(){$oldSubNav.css('display', 'none'); $newSubNav.css('display', 'block');});
					$('#subNavigationHolder').animate({'height': $('#subNavigationHolder #subnav-monu').outerHeight(true)}, 500, function(){if ($reload == 1){ location.reload(true); }});
				},"json");
			}
		}
	);
	
	$('#primary-navigation .selected .bg').css('display', 'block');
	
	$('.product-link .thumbnail').css('opacity', 0.5);
	$('#product-carousel .selected .thumbnail').css('opacity', 1);
	
	$('.product-link').hover(
		function () {
			if (!$(this).hasClass('selected')){
				$(this).stop();
				$(this).children('.thumbnail').stop();
				
				if ((Number($(this).attr('order')) + Number($('#product-carousel-set').attr('step')) - 9) > 0){
					$('#product-carousel-set').stop();
					$('#product-carousel-set').animate({'marginLeft': (Number($('#product-carousel-set').attr('step')) - (Number($(this).attr('order')) + Number($('#product-carousel-set').attr('step')) - 9)) * 76}, 250);
				}
				
				$(this).children('.thumbnail').animate({'opacity': 1}, 250);
				$(this).animate({'width': 217}, 250);
			}
		},
		function () {
			if (!$(this).hasClass('selected')){
				$(this).stop();
				$(this).children('.thumbnail').stop();
				$('#product-carousel-set').stop();
				$('#product-carousel-set').animate({'marginLeft': $('#product-carousel-set').attr('step') * 76}, 250);
				$(this).children('.thumbnail').animate({'opacity': 0.5}, 250);
				$(this).animate({'width': 65}, 250);
			}
		}
	);
	
	$('#product-carousel #leftArrow a').addClass('inactive');

	$('#product-carousel .arrow a').hover(
		function () {
			if (!$(this).hasClass('inactive')){
				$(this).addClass('over');
			}
		},
		function () {
			$(this).removeClass('over');
		}
	);
	
	$('#product-carousel #rightArrow a').click(
		function(e){
			e.preventDefault();
			if (!$(this).hasClass('inactive')){
				$('#product-carousel #leftArrow a').removeClass('inactive');
				$('#product-carousel-set').attr('step', Number($('#product-carousel-set').attr('step')) - 1);
				$('#product-carousel-set').animate({'marginLeft': $('#product-carousel-set').attr('step') * 76}, 250);
				if ($('#product-carousel-set').attr('step') <= (12 - $('#product-carousel-set').attr('count'))){
					$('#product-carousel #rightArrow a').addClass('inactive');
					$('#product-carousel #rightArrow a').removeClass('over');
				}
			}
		}
	);
	
	$('#product-carousel #leftArrow a').click(
		function(e){
			e.preventDefault();
			if (!$(this).hasClass('inactive')){
				$('#product-carousel #rightArrow a').removeClass('inactive');
				$('#product-carousel-set').attr('step', Number($('#product-carousel-set').attr('step')) + 1);
				$('#product-carousel-set').animate({'marginLeft': $('#product-carousel-set').attr('step') * 76}, 250);
				if ($('#product-carousel-set').attr('step') == 0){
					$('#product-carousel #leftArrow a').addClass('inactive');
					$('#product-carousel #leftArrow a').removeClass('over');
				}
			}
		}
	);
	
	$('.product-link').click(
		function(e){
			window.location = $(this).children('.detail').children('a').attr('href');
		}
	);
	
	
	$('.slide a').hover(
		function(){
			$(this).stop();
			$(this).animate({'marginLeft': '-191px'}, 300);
		},
		function(){
			$(this).stop();
			$(this).animate({'marginLeft': '0'}, 300);
		}
	);
	
	$('.slideIcon a').hover(
		function(){
			$(this).css({'marginLeft': '-32px'});
		},
		function(){
			$(this).css({'marginLeft': '0'});
		}
	);
	
	$('.slide a').click(
		function(e){
			e.preventDefault();
			if ($(this).attr('href') != '#'){
				window.location = $(this).attr('href');
			}
		}
	);
	
	$('.thumb .inner').hover(
		function(){
			if (!$(this).parent().hasClass('active')){
				$(this).stop();
				$(this).animate({'marginLeft': '-191px'}, 300);
			}
		},
		function(){
			if (!$(this).parent().hasClass('active')){
				$(this).stop();
				$(this).animate({'marginLeft': '0'}, 300);
			}
		}
	);
	$('.thumb .inner').click(
		function(e){
			e.preventDefault();
			window.location = $(this).parent().attr('href');
		}
	);
	
	
	$('.related .inner').hover(
		function(){
			$(this).stop();
			$(this).animate({'marginLeft': '-191px'}, 300);
		},
		function(){
			$(this).stop();
			$(this).animate({'marginLeft': '0'}, 300);
		}
	);
	$('.related .inner').click(
		function(e){
			e.preventDefault();
			window.location = $(this).parent().attr('href');
		}
	);
	
	
	
	$('#product-detail .photos').css('width', $('#product-detail .photos').children('.photo').length * 367);
	
	
	$('#product-detail #productPhotoNumbers .number a:first').addClass('selected');
	
	$('#product-detail #productPhotoNumbers .number a').click(
		function(e){
			e.preventDefault();
			$('#product-detail #productPhotoNumbers .number a.selected').removeClass('selected');
			$(this).addClass('selected');
			Cufon.replace('#product-detail #productPhotoNumbers .number a', {hover:true,hoverables:{a:true},fontFamily: 'EffraMedium'});
			$('#product-detail .photos').animate({'marginLeft': (1 - $(this).attr('id')) * 367}, 300);
			if ($('#darussafakaMug').length){
				
				if ($(this).attr('id') == 1){
					$('#darussafakaMug').html("");
				}
				if ($(this).attr('id') == 2){
					$('#darussafakaMug').html("");
				}
				if ($(this).attr('id') == 3){
					$('#darussafakaMug').html("");
				}
				if ($(this).attr('id') == 4){
					$('#darussafakaMug').html("Desen Eren Güzeloğlu tarafından çizilmiştir.");
				}
				if ($(this).attr('id') == 5){
					$('#darussafakaMug').html("Desen Ecem Saylan tarafından çizilmiştir.");
				}
				if ($(this).attr('id') == 6){
					$('#darussafakaMug').html("Desen Sumru Aytekin tarafından çizilmiştir.");
				}
				if ($(this).attr('id') == 7){
					$('#darussafakaMug').html("Desen Fatma Bingöl tarafından çizilmiştir.");
				}
				if ($(this).attr('id') == 8){
					$('#darussafakaMug').html("Desen Fatma Bingöl tarafından çizilmiştir.");
				}
				if ($(this).attr('id') == 9){
					$('#darussafakaMug').html("Desen Merve Acar tarafından çizilmiştir.");
				}
				
			}
		}
	);
	
	$('#news-detail .photos').css('width', $('#news-detail .photos').children('.photo').length * 444);
	
	
	$('#news-detail #productPhotoNumbers .number a:first').addClass('selected');
	
	$('#news-detail #productPhotoNumbers .number a').click(
		function(e){
			e.preventDefault();
			$('#news-detail #productPhotoNumbers .number a.selected').removeClass('selected');
			$(this).addClass('selected');
			Cufon.replace('#news-detail #productPhotoNumbers .number a', {hover:true,hoverables:{a:true},fontFamily: 'EffraMedium'});
			$('#news-detail .photos').animate({'marginLeft': (1 - $(this).attr('id')) * 444}, 300);
		}
	);
	
	
	$('#stores-menu #country').change(
		function(){
			$('#countryForm').submit();
		}
	);
	
	$('#stores-menu #city').change(
		function(){
			$('#cityForm').submit();
		}
	);
	
	$('#stores-menu #store').change(
		function(){
			$('#storeForm').submit();
		}
	);
	
	$('#stores-list .store:last').css('borderBottom', '0px');
	$('#stores-list .store:last').css('paddingBottom', '0px');
	$('#stores-list .store:last').css('marginBottom', '0px');
	
	$('#filterForm input[name=magazalar]').click(
		function(e){
			$show = $(this).is(':checked');
			$('.store').each(
				function(index){
					if ($(this).attr('type') == 'Mağaza'){
						if ($show){
							$(this).show();
						}
						else{
							$(this).hide();
						}
					}
				}
			);
		}
	);
	
	$('#filterForm input[name=cornerlar]').click(
		function(e){
			$show = $(this).is(':checked');
			$('.store').each(
				function(index){
					if ($(this).attr('type') == 'Corner'){
						if ($show){
							$(this).show();
						}
						else{
							$(this).hide();
						}
					}
				}
			);
		}
	);
	
	$('.store').each(
		function(index){
			if ($(this).attr('checkbox') == 'Corner'){
				$('#filterForm input[name=cornerlar]').attr('checked', true);
				$('#filterForm input[name=magazalar]').attr('checked', false);
			}
			if ($(this).attr('checkbox') == 'Mağaza'){
				$('#filterForm input[name=cornerlar]').attr('checked', false);
				$('#filterForm input[name=magazalar]').attr('checked', true);
			}
		}
	);
	

	$('#five-column .column').each(
		function(index){
			$marginTop = 0;
			if (index == 0){
				$marginTop = -17;
			}
			if (index == 1){
				$marginTop = -(index * $(this).css('height').substr(0, $(this).css('height').length - 2)) - 30;
			}
			if (index == 2){
				$marginTop = -(index * $(this).css('height').substr(0, $(this).css('height').length - 2)) - 42;
			}
			if (index == 3){
				$marginTop = -(index * $(this).css('height').substr(0, $(this).css('height').length - 2)) - 50;
			}
			if (index == 4){
				$marginTop = -(index * $(this).css('height').substr(0, $(this).css('height').length - 2)) - 67;
			}
			$(this).children('ul').css('marginTop', $marginTop + 'px');
		}
	);
	
	
	
	/*$('#five-column .column').each(
		function(index){
			$(this).children('ul').each(
				function(index1){
					$(this).children('li:first').css('marginTop', - (index + 1) * 17);
				}
			)
			
		}
	);
	
	$('#five-column .column').each(
		function(index1){
			$(this).children('ul').each(
				function(index2){
					$(this).children('li').each(
						function(index3){
							$(this).children('ul').each(
								function(index4){
									$(this).children('li').each(
										function(index5){
											if (index5 == 2){
												$(this).css('marginBottom', '15px');
											}
										}
									);
								}
							);
						}
					);
				}
			);
		}
	);*/
	
	
	$('#carouselController #rightArrow').click(
		function(e){
			e.preventDefault();
			if (!$(this).hasClass('inactive')){
				$('#carouselController #leftArrow').removeClass('inactive');
				$newSelected = $('#carouselController .selected').next();
				$('#carouselController .selected').removeClass('selected');
				$newSelected.addClass('selected');
				if (!$newSelected.next().hasClass('number')){
					$('#carouselController #rightArrow').addClass('inactive');
				}
				Cufon.replace('#carouselController', {hover:true,hoverables:{a:true},fontFamily: 'EffraMedium'});
				$('.carousel .thumbSets').animate({'marginLeft': -768 * $newSelected.attr('order')}, 250);
			}
		}
	);
	
	$('#carouselController #leftArrow').click(
		function(e){
			e.preventDefault();
			if (!$(this).hasClass('inactive')){
				$('#carouselController #rightArrow').removeClass('inactive');
				$newSelected = $('#carouselController .selected').prev();
				$('#carouselController .selected').removeClass('selected');
				$newSelected.addClass('selected');
				if (!$newSelected.prev().hasClass('number')){
					$('#carouselController #leftArrow').addClass('inactive');
				}
				Cufon.replace('#carouselController', {hover:true,hoverables:{a:true},fontFamily: 'EffraMedium'});
				$('.carousel .thumbSets').animate({'marginLeft': -768 * $newSelected.attr('order')}, 250);
			}
		}
	);
	
	$('#carouselController .number').click(
		function(e){
			e.preventDefault();
			if (!$(this).hasClass('selected')){
				$('#carouselController .selected').removeClass('selected');
				$(this).addClass('selected');
				if (!$(this).prev().hasClass('number')){
					$('#carouselController #leftArrow').addClass('inactive');
				}
				else{
					$('#carouselController #leftArrow').removeClass('inactive');
				}
				if (!$(this).next().hasClass('number')){
					$('#carouselController #rightArrow').addClass('inactive');
				}
				else{
					$('#carouselController #rightArrow').removeClass('inactive');
				}
				Cufon.replace('#carouselController', {hover:true,hoverables:{a:true},fontFamily: 'EffraMedium'});
				$('.carousel .thumbSets').animate({'marginLeft': -768 * $(this).attr('order')}, 250);
			}
		}
	);
	
	$('#newsletter-registration form').submit(
		function(e){
			e.preventDefault();
			
			$form = $(this);
			$email = $form.find('input[name="email"]').val();
			$url = $form.attr('action');
			
			$.post($url, {email: $email},
				function(data) {
					$form.find('input[name="email"]').val(data);
				}
			);
		}
	);
	
	

});



