/*

v.0001 
Date:  23.11.2010 21:47:56 (GMT)
developed by: DevLeader
site: http://devleader.net

*/
jQuery.fn.loadproject = function(options){
	var options = jQuery.extend({
	    object:null,
	    currentProj:0,
	    firstquery :true
  },options);
	return this.each(function() {
		options.object = this;
		$(this).bind('click',function(){
			getProejct(this);
			return false;
		});
	});
	function getProejct(obj){
		var url = $(obj).attr('href');
		if (!url) return false;
		showloading();
		var atitle= $(obj).attr('title');
		options.currentProj = url;

		$('#project-content').animate({opacity:0},((options.firstquery)?0:500),null,function(){
			$.post(url,null,function(data){processProject(data);},"json");
		});
	};
	function processProject(data){
		if (!data) return;
		if (!data['url']) return;
		if (data.url != options.currentProj) return;
		$('#screen-shoot').empty();
		document.title = data.title + ' - ' +_sitename;
		if (data.www) $('#site-link').find('a').attr('href',data.www);
			else $('#site-link').find('a').hide();
		$('#site-title').html(data.title);
		
		if (!data.text) {
			$('#description').hide(); 
		} else {
			$('#description').show(); 
			$('#description-text').html(data.text);
		}
		var chk = false;
		$('#techs').empty();
		if (typeof(data.tech) == 'object'){
			for(var i in data.tech){
				chk = true;
				$('#techs').append($('<img />').attr('src',_basepath+'media/icons/'+data.tech[i].file).attr('alt',data.tech[i].title).attr('title',data.tech[i].title));
			}
		}
		(chk) ? $('#techs').show() : $('#techs').hide();
		var chk = false;
		$('#project-images').empty();
		if (typeof(data.images) == 'object'){
			for(var i in data.images){
				chk = true;
				$('#project-images').append(
				
					$('<img />').attr('src',_basepath+'media/images/project-183x181-'+data.id+'-'+data.images[i].gid+'.'+data.images[i].extension)
									.attr('alt',data.title).attr('title',data.title).attr('rel',data.id+'-'+data.images[i].gid+'.'+data.images[i].extension)
									.bind('click',function(){
										var img = $('<img >').attr('src',_basepath+'media/images/project-554x423-'+$(this).attr('rel')).attr('rel',$(this).attr('rel')).bind('click',function(){
											$('#'+$(this).attr('rel').replace('.','')).click();
										});
										$('#screen-shoot').html(img);
									})
					).append($('<a></a>').attr('rel','cb').attr('href',_basepath+'media/images/project-'+data.id+'-'+data.images[i].gid+'.'+data.images[i].extension).attr('id',data.id+'-'+data.images[i].gid+data.images[i].extension));
			}
		}
		if (!options.firstquery){
			var x = $('#project-info').offset().top - 50;
			$('html, body').animate({scrollTop:x}, 'slow');
		}
		$('#project-content').animate({opacity:1},1000,null,function(){
			$('#project-images img:first').click();
			$("#project-images a[rel=cb]").colorbox();
			hideloading();
			options.firstquery = false;
		});
	};
	function showloading(){
		$('#project-loader').removeClass('hidden');
	};
	function hideloading(){
		$('#project-loader').addClass('hidden');
	};
	
};
