$(document).ready(function(){

  $.preload([ 'co2cut', 'cms', 'salveta', 'razbor', 'pametnakuna', 'attack', 'bozoo', 'cekate', 'countryboys', 'css', 'ekviva', 'halter', 'kit', 'kupijeftinije', 
              'lorr', 'skaramuzi', 'split', 'stocitas', 'tocka', 'tref', 'valgrad' ], {
    base:'images/',
    ext:'.jpg'
  });
	
	var id = 0
	var total = 17
	
	$('#previous, #next').click(function(){
		
		if(this.id == 'previous')		id = id - 1
		if(this.id == 'next') 			id = id + 1
		if(id > total) 					id = 1
		if(id == 0 || id == -1)			id = total
		
		$.ajax({
			type: "GET",			
			success: function(){						
				  
				$.getJSON("ajax_project?id=" + id, function(json) {
					
					$("#project img").fadeOut();
					
					timeout = setTimeout(function() {
						
						if(json.url) {
							$("#info").replaceWith('<div id="info"><h2>' + json.title + '</h2>' + json.txt + '<a href="' + json.url + '">link na site</a></div>');
						} else {
							$("#info").replaceWith('<div id="info"><h2>' + json.title + '</h2>' + json.txt + '</div>');
						}
						if(json.image) {
							$("#project").replaceWith('<div id="project"><a href="'+ json.url +  '"><img src="../images/' + json.image + '" alt="' + json.title + '"></a></div>')
						} else {
							$("#project").replaceWith('<div id="project"></div>');
						}
						
						$("#project img").hide();
						$("#project img").fadeIn();
						
					}, 300);				
					
				});  
			  
			}
		});
		return false;
	});
	
	$('.more').click(function(){
		 $.ajax({
			type: "GET",
			url: "ajax_txt",
			data: "type=" + this.id,
			success: function(msg){			  
			  
			  $("#project").fadeOut();
			  
			  timeout = setTimeout(function() {
					$("#project").replaceWith('<div id="project">' + msg + '</div>');
					$("#project").addClass('text_background');
					$("#project").hide();
					$("#project").fadeIn();				
			  }, 300);
			}
		  });
		  return false;
	});
	
});
