$(document).ready(function() {
	
		$(".gallery_img").fancybox({
				'autoScale'			: true,
				'cyclic'			: true,
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'image',
				'autoDimensions'	: true,
				'titleShow'			: true,
				'titlePosition'		: 'over',
				'overlayColor'		: '#000'
			});
			
		$(".karta_img").fancybox({
				'autoScale'			: true,
				'cyclic'			: true,
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'image',
				'autoDimensions'	: true,
				'titleShow'			: false
		});


		$(".gmap_link").fancybox({
			'width'				: 445,
			'height'			: 370,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe',
			'autoDimensions'	: false,
			'titlePosition'		: 'over'
		});
			
		$(".header_prijava").fancybox({
			'width'				: 480,
			'height'			: 300,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'titleShow'			: false,
			'overlayColor'		: '#000',
			'padding'			: 0
		});
		
		
		$(".show_img").fancybox({
			'autoScale'			: true,
			'cyclic'			: true,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'image',
			'autoDimensions'	: true,
			'titleShow'			: false,
			'overlayColor'		: '#000'
		});
		
		$(".prijava_popup").fancybox({
			'width'				: 480,
			'height'			: 365,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'titleShow'			: false
		});
		
		$(".komentiraj_popup").fancybox({
			'width'				: 480,
			'height'			: 365,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'titleShow'			: false
		});
		
		$.fn.wait = function(time, type) {
	
	        time = time || 1000;
	
	        type = type || "fx";
	
	        return this.queue(type, function() {
	
	            var self = this;
	
	            setTimeout(function() {
	
	                $(self).dequeue();
	
	            }, time);
	
	        });
	
	    };
		
		
		$('#slider')
		.anythingSlider({
			width               : 600,
			height              : 400,
			startStopped        : false,
			buildNavigation     : false,
			enablePlay          : true,
			startText           : "",
			stopText            : "",
			hashTags            : false,
			delay               : 5000,      // How long between slideshow transitions in AutoPlay mode (in milliseconds)
			animationTime       : 1000       // How long the slideshow transition takes (in milliseconds)
	
		})
		.anythingSliderFx({
			inFx: {
				'.caption-top'    : { top: 0, opacity: 1, time: 1000 },
				'.caption-right'  : { right: 0, opacity: 1, time: 1000 },
				'.caption-bottom' : { bottom: -315, opacity: 1, time: 1000 },
				'.caption-left'   : { left: 0, opacity: 1, time: 1000 }
			},
			outFx: {
				'.caption-top'    : { top: -50, opacity: 0, time: 1000 },
				'.caption-right'  : { right: -150, opacity: 0, time: 1000 },
				'.caption-bottom' : { bottom: -350, opacity: 0, time: 1000 },
				'.caption-left'   : { left: -150, opacity: 0, time: 1000 }
			}
		})
		.find('div[class*=caption]')
			.css({ position: 'absolute' })
			.prepend('<span class="close">x</span>')
			.find('.close').click(function(){
				var cap = $(this).parent(),
					ani = { bottom : -50 }; // bottom
				if (cap.is('.caption-top')) { ani = { top: -50 }; }
				if (cap.is('.caption-left')) { ani = { left: -150 }; }
				if (cap.is('.caption-right')) { ani = { right: -150 }; }
				cap.animate(ani, 400, function(){ cap.hide(); } );
			});
		
		
		
		$(function() {
		var galleries = $('.ad-gallery').adGallery({
			effect: 'fade',
			loader_image: '../../../images/loader.gif'
		});
		$('#switch-effect').change(
		  function() {
			galleries[0].settings.effect = $(this).val();
			return false;
		  }
		);
		$('#toggle-slideshow').click(
		  function() {
			galleries[0].slideshow.toggle();
			return false;
		  }
		);
		$('#toggle-description').click(
		  function() {
			if(!galleries[0].settings.description_wrapper) {
			  galleries[0].settings.description_wrapper = $('#descriptions');
			} else {
			  galleries[0].settings.description_wrapper = false;
			}
			return false;
		  }
		);
	  });
		
		
});

function spremi_u_kosaricu(id, user_id, sess_id, head, url_path){
	$.ajax({
	  type: 'POST', 
	  data: ({id : id, user_id : user_id, sess_id : sess_id}),
	  url: ''+url_path+'/ajax/dodaj_u_kosaricu.php',
	  success: function(data) {
	    //$('#artikl_poruka_'+id+'').slideDown('slow');
	    window.location.href = url_path+'/kosarica/';
	  }
	});
	/*$.ajax({
	  type: 'POST', 
	  data: ({id : id, user_id : user_id, sess_id : sess_id}),
	  url: ''+url_path+'/ajax/kosarica_pregled.php',
	  success: function(data) {
	    $('#header_kosarica_txt').html(data);
	  }
	});*/
}

function removeValue(id , provjera){
    var value = document.getElementById(id).value;
    if(value==provjera){document.getElementById(id).value="";}
}

function dostava_odabir_adrese(id,id2) {
	if(window.document.getElementById(id2).checked == true){
		//alert('da');
		window.document.getElementById(id).style.display = 'inline';
	} else {
		//alert('ne');
		window.document.getElementById(id).style.display = 'none';
	}
}
