

$(document).ready(function() {
						   
						   
 			

	$('#headerimg').click(function() {window.location.href = '/'});


	// add bubbles to polaroids.
	
	$('#polaroid-piotr').click(function() 
		{
			if ($('#balloon-konrad').is(":visible")) $('#balloon-konrad').hide();
			if ($('#balloon-piotr').is(":visible")) 
			{
				$('#balloon-piotr').hide();
			}
			else 
			{
				$('#balloon-piotr').show();
			}
		});
	
	$('#polaroid-konrad').click(function() 
		{
			if ($('#balloon-piotr').is(":visible")) $('#balloon-piotr').hide();
			if ($('#balloon-konrad').is(":visible")) 
			{
				$('#balloon-konrad').hide();
			}
			else 
			{
				$('#balloon-konrad').show();
			}
		});
		



	//lets try to attach stupid fb like button ;-)

	//var entry = $('body.single .entry');
	//var permalink = $('.post-header').find('a').attr('href');
	//var postTitle = $('.post-header').find('a').text();
	//var images = entry.find('img.size-full');

//	$.each(images || [], function (id, image) 
	//{
//		var img = $(image);
//		var imageID = null;
//		var classList = img.attr('class');
//		var classArray = classList.split(" ");
//		$.each(classArray || [], function(as, domclass)
//		{
//			var isID = domclass.indexOf("wp-image");
//			if (isID > -1) imageID = domclass.replace("wp-image-","");

//		});
		//found id? 
//		if (imageID) 
//		{
//			img.before('<a name="' + imageID + '" id=' + imageID + '"></a>');
//			var width = img.width();
//			
//			var destlink = "http://visual-obsession.com/xpic/" + imageID;
//			if (width == 900) 
//			{
//				var uri=window.location.href.split("?");
//				if (uri[1] == "who") 
//				{			
//					img.after('<fb:like href="' + destlink + '" layout="standard" /></fb:like>');
//				}
//				else
//				{
//					img.after('<fb:like href="' + destlink + '" layout="button_count" show_faces="false"></fb:like>');
//				}
//			}
//		
//		}
//					   
//	});


	var categoriesBubble = $('#categories-box');
	var informationBubble = $('#information-box');
	var connectBubble = $('#connect-box');
	
	var categories = $('#categories');
	var information = $('#information');
	var connect = $('#connect');
	
	positionMenu(categoriesBubble);
	positionMenu(informationBubble);
	positionMenu(connectBubble);
	

	$('#connect img').hover(function()	{ this.src = this.src.replace("-off","-on");},function() {	if (!isVisible(connectBubble)) this.src = this.src.replace("-on","-off"); 	});
	$('#information img').hover(function()	{ this.src = this.src.replace("-off","-on");},function() {	if (!isVisible(informationBubble)) this.src = this.src.replace("-on","-off"); 	});
	$('#categories img').hover(function()	{ this.src = this.src.replace("-off","-on");},function() {	if (!isVisible(categoriesBubble)) this.src = this.src.replace("-on","-off"); 	});
		
	categories.click(function (e) {
							e.preventDefault();
							
							if (isVisible(categoriesBubble))  
							{ //categories are open .. lets close. 
								
								categoriesBubble.hide();
								e.target.src = e.target.src.replace("-on","-off");	
							} 
							else 
							{  // categories are closed. lets open.
							if (isVisible(connectBubble)) {connectBubble.hide(); $("#connect img").hover(false); }
							if (isVisible(informationBubble)) {informationBubble.hide(); $('#information img').hover(false); }
							categoriesBubble.show();
							e.target.src = e.target.src.replace("-off","-on");	

							}	
							
							});
	categoriesBubble.mouseleave(function (e) {
									categoriesBubble.hide();
									 $('#categories img').hover(false);
									});

	information.click(function (e) {
				  			e.preventDefault();
							
							if (isVisible(informationBubble))  
							{ //categories are open .. lets close. 
								
								informationBubble.hide();
								e.target.src = e.target.src.replace("-on","-off");	
							} 
							else 
							{  // categories are closed. lets open.
							if (isVisible(categoriesBubble)) {categoriesBubble.hide();  $('#categories img').hover(false); }
							if (isVisible(connectBubble)) {connectBubble.hide(); $('#connect img').hover(false); }
							informationBubble.show();
							e.target.src = e.target.src.replace("-off","-on");	
							}
							});
	informationBubble.mouseleave(function (e) {
									informationBubble.hide();
									 $('#information img').hover(false);
									});
	
	connect.click(function (e) {
				  			e.preventDefault();
							if (isVisible(connectBubble))  
							{ //categories are open .. lets close. 
								
								connectBubble.hide();
								e.target.src = e.target.src.replace("-on","-off");	
							} 
							else 
							{  // categories are closed. lets open.
							if (isVisible(categoriesBubble)) {categoriesBubble.hide();  $('#categories img').hover(false); }
							if (isVisible(informationBubble)) {informationBubble.hide(); $('#information img').hover(false); }
							connectBubble.show();
							e.target.src = e.target.src.replace("-off","-on");	
							}
							});
	connectBubble.mouseleave(function (e) {
									connectBubble.hide();
									 $('#connect img').hover(false);
									});
	

	function isVisible(bubble)
	{
		return bubble.is(':visible');
	}
	

	function positionMenu(div) 
	{
		var height = div.height();
		var pos = 0 - 20 - height;
		div.css("top",pos);
	}
	
	

	$('#imagerotator').cycle({
		fx: 'fade' ,
		timeout: 6000, 
		speed: 2000
	});
 
		
	$("#imageSearch").autocomplete("/wp-content/themes/vo/ajaxsearch.php", {
		width: 270,
		max: 20,
		highlight: false,
		scroll: true,
		scrollHeight: 300,
		formatItem: function(data, i, n, value) {
			url = value.split("*%PTC$#")[0];
			title = value.split("*%PTC$#")[1];
			result = "<div style='width: 100px'><img src='" + url + "' height='50'/></div> " + title;
			return result;
		
		},
		formatResult: function(data, value) {
			//to co jest wstawiane w box po kliknieciu
			//return value.split(".")[0];
			return value.split("*%PTC$#")[1];
		}
	});


	//add text to bubbles etc. stuff that's not visible to fb
	
	var konrad = "Man, what do I write? =). I like to take pictures.... a lot =D. On a serious note, photography and graphic design are my life passions I can't imagine parting with. If you want to get to know me on a bit more personal level <a href='http://facebook.com/konrad.krukowski' target='_blank'>Facebook</a> or <a href='http://twitter.com/konradkrukowski' target='_blank'>Twitter</a>.";
	
	var piotr = "I'm a photographer and a programmer. <br /><br /> If you want to find out a little bit more shoot me an email, visit my <a href='http://facebook.com/piotr.nowak' target='_blank'>Facebook</a> page or follow me on <a href='http://twitter.com/PiotrNowak' target='_blank'>Twitter</a>";
	$("#balloon-konrad").html(konrad);
	$("#balloon-piotr").html(piotr);
	
	


});



	
	
	
	
