(function(){
	ua = navigator.userAgent.toLowerCase(),	  
	check = function(r){
		return r.test(ua);
	}
	isOpera = check(/opera/),			  
	isIE = check(/msie/),
	isIE7 = isIE && check(/msie 7/),
	isIE8 =	isIE && check(/msie 8/),
	isIE6 =	isIE && !isIE7 && !isIE8,
	isChrome = check(/chrome/),
	isWebKit =check(/webkit/),
	isSafari =!isChrome && check(/safari/),
	isSafari2 =	isSafari && check(/applewebkit\/4/),
	isSafari3 = isSafari && check(/version\/3/),
	isSafari4 = isSafari && check(/version\/4/),
	isGecko = !isWebKit && check(/gecko/),
	isGecko2 = isGecko && check(/rv:1\.8/),
	isGecko3 = isGecko && check(/rv:1\.9/),
	isWindows = check(/windows|win32/),	
	isMac = check(/macintosh|mac os x/),	
	isAir = check(/adobeair/),	
	isLinux = check(/linux/),
	
	
	jQuery.extend(jQuery.browser, {
		isOpera: isOpera,
		isIE:	isIE,
		isIE6: isIE6,
		isIE7: isIE7,
		isIE8: isIE8,
		isChrome: isChrome,
		isWebKit: isWebKit,
		isSafari: isSafari,
		isSafari2: isSafari2,
		isSafari3: isSafari3,
		isSafari4: isSafari4,
		isGecko: isGecko,
		isGecko2: isGecko2,
		isGecko3: isGecko3,
		isWindows: isWindows,
		isMac: isMac,
		isAir: isAir,
		isLinux: isLinux
	});
	
	jQuery.extend({
	  addStyle: function(path){
		var style = document.createElement('link');
		style.setAttribute('rel','stylesheet');
		style.setAttribute('type','text/css');
		style.setAttribute('href',path);
		document.getElementsByTagName('head')[0].appendChild(style)	;	  
	  }, 	  
	  
	  parseQuery: function(url) {
		   var query = url.replace(/^[^\?]+\??/,'');
		   var Params = {};
		   if ( ! query ) {return Params;}// return empty object
		   var Pairs = query.split(/[;&]/);
		   for ( var i = 0; i < Pairs.length; i++ ) {
		      var KeyVal = Pairs[i].split('=');	
		      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
		      var key = unescape( KeyVal[0] );
		      var val = unescape( KeyVal[1] );
		      val = val.replace(/\+/g, ' ');
		      Params[key] = val;
		   }
		   return Params;		  
	  }	  
	});

})();

function load_projects(page, next_count){
	if (next_count <=0 ) page = 0;
	$('#loading-index').show();
	var next_page = parseInt(page)+1;
	$.ajax({
		url: '../includes/get-projects.php',
		data: {
			'page': next_page
		},
		type: 'post',
		dataType: 'json',
		success: function(rs){
			$('#loading-index').hide();
			var visible = $('#more-projects').css('display');
			if (next_page > rs['page_count']) next_page = 1;
			$('#see-more a').attr('rel', next_page + '#' + rs['next_count']);
			var text = 'See more projects...';
			$('#see-more a').text(text);
			if ('none' == visible) {
				$('#more-projects').html(rs['projects']);
				$('#projects').fadeOut(800);
				$('#more-projects').fadeIn(800);
			} else {
				$('#projects').html(rs['projects']);
				$('#more-projects').fadeOut(800);
				$('#projects').fadeIn(800);
			}
			$('#see-more a').bind('click', see_more);
		}
	});
}

function see_more(){
		$(this).unbind('click');
		var rel = $(this).attr('rel');									
		rel = rel.split('#');
		load_projects(rel[0], rel[1]);		
		return false;	
}

$(document).ready(function(){
	var h = $('#projects').height();	
	$('#see-more a').bind('click', see_more);
 	if ($.browser.isIE6) {
		DD_belatedPNG.fix(".ie6fix");
	}
});
