﻿$(document).ready(function() {

 $("#q").autocomplete("/autocomplete.ashx"); 

//** main menu **//
		

    $('ul#main-links li').hover(
			function() { 
			

if ($('ul',this).is(':hidden')) {
    $('ul',this).slideDown(300);
} 			},
			
			
			function() { 
			

if ($('ul',this).is(':visible')) {
    $('ul',this).slideUp(100);
} 			}		
			
			);


//** acilir kapanir **//
		
	$('#toggle a').click(function() {
		var toggleelement = this
		var toggleid = $(toggleelement).attr('name'); 
		$('#'+toggleid).toggle(500); 
		return false; 
	}); 


//** ajax formlar **//
			
//	$('#ajax_submit').click(function () {		
				
//		var gideceksayfa = $('form').attr('action');
//		var veriler= $('form').serialize();		
		
//		$('form').attr('disabled','true');
//		$('form').slideUp('slow');	
//		$('#sonuc').html('<p><img src="/page_images/anim-loading.gif"/> Lütfen Bekleyiniz</p>');
				
//		$.ajax({
//			type: 'GET',
//			url: gideceksayfa,
//			data: veriler,
//			cache: false,
//			success: function (gostert) {				
//				$('#sonuc').html(gostert);
//			}		
//		});	
//	
//	return false;
//	});




//** add to cart **//
			
	$('.content-add-to-cart-jx').click(function () {		
		
		var element = this
		var id = $(element).attr('name'); 

		
		var gideceksayfa = $('#content-add-to-cart-form'+id).attr('action');
		var veriler= $('#content-add-to-cart-form'+id).serialize();		
		
		$('#content-add-to-cart-form'+id).attr('disabled','true');
		$('#content-add-to-cart-form'+id).slideUp('slow');	
		$('#content-add-to-cart-result'+id).html('<img src="/page_images/anim-loading.gif"/>');
		$('#cart-summary-view-cart').toggle(500);		
		$.ajax({
			type: 'GET',
			url: gideceksayfa,
			data: veriler,
			cache: false,
			success: function (gostert) {				
				$('#cart-summary-view-cart').html(gostert).toggle(500);
				$('#content-add-to-cart-result'+id).html("Item successfully added to your cart. <a href='shop_checkout.aspx'>Checkout NOW!</a>");
			}		
		});	
	
	return false;
	});


//** show hide**//

   
	$('p.showhide a').click(function() {
		var element = this
		var id = $(element).attr('name'); 
		$('#hiddendiv' + id+',p#show' + id + ',p#hide' + id).toggle(500); 
		return false; 
	}); 


/*
latest news scroller
*/
	var height = 0;
			var to = null;
			var theAnimation;
			var newsScroller;
			$(document)
			.ready(function(){
				newsScroller = $('#newsScroller');
				
				var curSet = newsScroller
				.prev()
					.addClass('ns')
				.end()
				.wrap('<div>')
				.parent()
					.addClass('ns')
				.end()
				.wrap('<div>')
				.children()
				.slice(0,2)
				.each(function(){
					height += $(this).outerHeight(true);
				});
				
				theAnimation = function(){
					if( !newsScroller.is(':animated') ){
						newsScroller.animate({top:-height},1000,function(){
							height = 0;
							curSet = newsScroller
							.append(curSet)
							.css('top',0)
							.children()
							.slice(0,2)
							.each(function(){
								height += $(this).outerHeight(true);
							});
						});
					}
				};
				
				to = setInterval(theAnimation,4000);
							
				newsScroller.bind('mouseenter',function(){
					clearInterval(to);
				})
				.bind('mouseleave',function(){
					to = setInterval(theAnimation,4000);
				});
			});

/*
browse all news
*/
    $('.link').toggle(   
        function () {   
            if($('#news-box').text() == '') {   
                $.ajax({   
                    url:'/latest_news.ashx',   
                    method:'GET',   
                    success:function(r) {   
                        $('.link').html('CLOSE LIST');   
                        $('#news-box').html(r).hide().slideDown(1000);   
                    },   
                    error:function() {   
                        alert('file does not exist');   
                    }   
                });   
            } else {   
                $(this).html('CLOSE LIST');   
                $('#news-box').slideDown(1000);   
            }   
        },   
        function () {   
            $(this).html('LIST VIEW');   
            $('#news-box').slideUp(1000);   
        }   
    );   


/*
carousel
*/
	jQuery('#mycarousel').jcarousel();
	


 //** light box**//

       $('#photo a,#photo-gallery a').lightBox();
       $('#photo_multimedia a').lightBox();


//** show hide**//
   
	$('p.showhide a').click(function() {
		var element = this
		var id = $(element).attr('name'); 
		$('#hiddendiv' + id+',p#show' + id + ',p#hide' + id).toggle(500); 
		return false; 
	}); 
	
//** font-size **//	
	$("#large-font a").click(function(event){   
	event.preventDefault(); 
	$("#normal-font,#large-font").toggle(400);
	$("p,ul li").css("font-size","13px");   
	});   	
	
	$("#normal-font a").click(function(event){   
	event.preventDefault(); 
	$("#normal-font,#large-font").toggle(400);
	$("p,ul li").css("font-size","11px");   
	});   	
	
	
	
//** sadece sayi **//	
	$("#qty").keyup(function() {
		var cleana=$("#qty").val();
		cleana = cleana.replace(/[^0-9 ]/gi, "");
		$('#qty').val(cleana);
	});
	
	
//** toggle shipping address **//		
		$("p#shipping-address-check input[type='checkbox']").click(function () {
			$("#shipping-address").toggle(400);
		});
	
	
});	
