jQuery(document).ready(function($) {
	
	var config = {
		likebox : {
			href : 'http://www.facebook.com/pages/Bebeloo/150328331688919',
			width : '292',
			colorscheme : 'light',
			show_faces : 'true',
			stream : 'false',
			header : 'false',
			height : 300
		},
		comments : {
			api_key : '113869198637480',
			channel_url : 'http%3A%2F%2Fstatic.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%3Fversion%3D0%23cb%3Df8a9cf8a4%26origin%3Dhttp%253A%252F%252Fdevelopers.facebook.com%252Ff37fe73b28%26relation%3Dparent.parent%26transport%3Dpostmessage',
			href : 'bebeloo.ro',
			locale : 'en_US',
			numposts : 2,
			sdk : 'joey',
			width : 500,
			height : 300
		}
	}
	
	var sample = {
		likebox : '<div class="outer"><div class="inner"><span><iframe src="http://www.facebook.com/plugins/likebox.php?%params%" ' + 
					'scrolling="no" frameborder="0" style="border:none; overflow:hidden;" allowTransparency="true"></iframe></span></div></div>',
		comments : '<div class="outer"><div class="inner"><span><iframe src="http://www.facebook.com/plugins/comments.php?%params%" ' + 
					'scrolling="yes" frameborder="0" style="border-width:initial;border-color:initial;overflow:hidden;border:none;"></iframe></span></div></div>'
	}
	
	$('.facebook-likebox, .facebook-comments').each(function(){
		if (!$(this).attr('width')) {
			$(this).attr('width', $(this).width());
		}
		if (!$(this).attr('height')) {
			$(this).attr('height', $(this).height());
		}
	})
	
	$('.facebook-likebox').each(function(){
		var params=""
		for (var key in config.likebox) {
			params += key + '=' + (($(this).attr(key)) ? $(this).attr(key) : config.likebox[key]) + '&';
		}
		$(this).html(sample.likebox.replace('%params%', params))
		$('iframe', this).css({
			width: ($(this).attr('width')) ? $(this).attr('width') + 'px' : config.likebox['width'],
			height: ($(this).attr('height')) ? $(this).attr('height') + 'px' : config.likebox['height']
		})
	})
	
	window.facebook_comments_mover_current = null;
	$('.facebook-comments').each(function(){
		var params=""
		for (key in config.comments) {
			params += key + '=' + (($(this).attr(key)) ? $(this).attr(key) : config.comments[key]) + '&';
		}
		$(this).html(sample.comments.replace('%params%', params))
		$('iframe', this).css({
			width: ($(this).attr('width')) ? $(this).attr('width') + 'px' : config.comments['width'],
			height: ($(this).attr('height')) ? $(this).attr('height') + 'px' : config.comments['height']
		}).mouseover(function(){
			if ($('#facebook-comments-expand').length == 0) {
				$(document.body).append('<div id="facebook-comments-expand"><a href="javascript:;"></a></div>');
			}
			window.facebook_comments_mover_current = this
			$('#facebook-comments-expand')
				.attr('mouseover', 1)
				.css({
					top : ($(this).parents('.facebook-comments').position().top + $(this).height() - 40) + 'px',
					left : ($(this).parents('.facebook-comments').position().left + $(this).width() - 40) + 'px'
				})
				.mouseover(function(){ $(this).attr('mouseover', 1) })
				.mouseleave(function(){ $(this).attr('mouseover', 0) })
			.click(function(){
				if (!facebook_comments_mover_current) return
//				v-0.1
//				var w = window.open(
//								facebook_comments_mover_current.src.replace(/&height=\d+/, '').replace(/&width=\d+/, '&width=440')
//								,'mywindow','width=450,height=720,scrollbars=yes')
//				v-0.2
				var w = window.open('javascript:;','mywindow','width=450,height=610'), p = $(facebook_comments_mover_current).parents('.facebook-comments')
				w.document.writeln('<html><head><title>Bebeloo :: Facebook Comments</title></head><body bgcolor=white"><iframe></iframe></body></html>');
				$(w.document.body).css({
					backgroundColor : 'white'
				});
				$('iframe', w.document.body)
					.css({
						border : 0,
						width : $(window.facebook_comments_mover_current).innerWidth() + 'px',
						height : '720px'
					})
					.attr('src', window.facebook_comments_mover_current.src.replace(/&height=\d+/, ''))
					.attr('id', 'f1a9e0b5ec').attr('name', 'ffb11a7c').attr('scrolling', 'yes')
					.addClass('fb_ltr')
			})
		}).mouseleave(function(){
			$('#facebook-comments-expand').attr('mouseover', 0)
			setTimeout(function(){ 
				window.facebook_comments_mover_current = null;
				if ($('#facebook-comments-expand').attr('mouseover') && $('#facebook-comments-expand').attr('mouseover') != 1) { 
					$('#facebook-comments-expand').hide(200, function(){ $(this).remove(); }); 
				}
			}, 1000);
		})
	})

	var x = (Math.random() > 0.5) ? 1 : 0;
	$('.list_product_position_home:eq(' + x + ')').hide();
	
	
	
//	$.getScript("http://connect.facebook.net/en_US/all.js#xfbml=1")
});



