 $(document).ready(function() {
	var pHeight = $('#posts').height();
	var sHeight = $('#sidebar').height()+290;
	var path = window.location.pathname;

	if(((path.substring(0, 5) == "/page/") || (path == "/")) || (path.substring(0, 14) == "/zexteam/page/") || (path == "/zexteam/")){
		if(pHeight>sHeight){
			$('#content').height(pHeight+302);
			$('#sidebar').height(pHeight-20);
		}else{
			$('#content').height(sHeight+302);
		}
	}else{
		if(pHeight>sHeight){
			$('#content').height(pHeight);
			$('#sidebar').height(pHeight-20);
		}else{
			$('#content').height(sHeight);
		}
	}
	
	$( "#post-table" ).accordion({ autoHeight: false, collapsible: true, active: false });

	$( "#sidebar .widgets #categories-2 ul" ).accordion( {
		autoHeight: false, 
		collapsible: true, 
		active: false, 
		event: "mouseover"
	});	
	
	$("#posts-content").accordion();	
	
	$("a[rel='post-pics']").colorbox();
	
	$(".menu_item").tooltip({ 
				position: "top center",
				offset: [10,-281],
				opacity: 0.9
			});
	
	// main vertical scroll
	$("#main").scrollable({
		// basic settings
		vertical: true
	}).navigator("#main_navi");
	
	$( "#posts-full-tabs" ).tabs();
});

function getPreview(setid){
	var url = "http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=45145931d7c9b5687a549033bf28d7cd&photoset_id="+setid+"&format=json&jsoncallback=?";
	$.getJSON(
		url,
		{tags: "cat",tagmode: "any",format: "json"},
		function(data) {
			$.each(data.photoset.photo, function(i,item){							
				var pId = item.id;
				var pFarm = item.farm;
				var pServer = item.server;
				var pSecret = item.secret;
				var pURL = 'http://farm' + pFarm + '.static.flickr.com/' +pServer + '/' + pId + '_' + pSecret + '_s.jpg';				
				var img = $('#'+pId);				
				img.attr("src", pURL );
			});
		}
	);
}

function getGallery(setid, preview){
	var url = "http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=45145931d7c9b5687a549033bf28d7cd&photoset_id="+setid+"&format=json&jsoncallback=?";
	$.getJSON(
		url,
		{tags: "cat",tagmode: "any",format: "json"},
		function(data) {
			var images = "";
			$.each(data.photoset.photo, function(i,item){	
				var pId = item.id;
				if(pId!=preview){
					var pTitle = item.title;
					var pFarm = item.farm;
					var pServer = item.server;
					var pSecret = item.secret;
					var pURL = 'http://farm' + pFarm + '.static.flickr.com/' +pServer + '/' + pId + '_' + pSecret + '_b.jpg';
					var tURL = 'http://farm' + pFarm + '.static.flickr.com/' +pServer + '/' + pId + '_' + pSecret + '_s.jpg';
					images = images + '<a href="'+pURL+'" rel="'+setid+'" title="'+pTitle+'"><img src="'+tURL+'" class="gallery-image"></a>';
				}
			});
			var div = $('#gallery-'+setid);
			div.append(images);
			$("a[rel='"+setid+"']").colorbox();
		}
	);
}

