var spinner_tabs = '<img src="/img/indicator12_tabs.gif" width="12" height="12" />';
var spinner_dark = '<img src="/img/indicator12_dark.gif" width="12" height="12" />';
var spinner_white = '<img src="/img/indicator12.gif" width="12" height="12" />';

$(document).ready(function() {
	$('input[type="text"]').field();
	$('textarea').field();
	$('textarea').autogrow();
	
	// Facebook Share fix
	 jQuery(document).ready(function(){
	 jQuery("span.fb_share_no_count").each(function(){
	   jQuery(this).removeClass("fb_share_no_count");
	   jQuery(".fb_share_count_inner", this).html("0");
	 });
	});

	$('#toggleh1').click(function() {
		//$('div.signin').toggle();

		var elem = $('div.signin'); 
		if(elem.css('display') == 'none') 
			 elem.show(); 
		else 
			 elem.hide();

		$('.signin_arrow').toggle();
	});

	$("div.signin a.minibutton").click(function() {
		$("div.signin form").submit();
		return false;
	});

	$('search_btn').click(function() {
		$('.search form').submit();
		return false;
	});

	$('.slide_close').click(function() {
		$('.slide_container').slideUp();
		return false;
	});

	BindThumbnails($('body'));

	$("div.showhide").hide();

	$('#toggleh2').click(function() {
		$('div.showhide').slideToggle();
	});

	$('a[name="fb_share"]').click(function() {
		var u=location.href;
		var t=document.title;

		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');

		return false;
	});
});

$.fn.field = function() {
	$(this).css({color: '#999999'});

	return this.focus(function() {
		if ($(this).val() == this.defaultValue) {
			$(this).val('');
			$(this).css({color: '#333333'});
		}
	}).blur(function() {
		if (!$(this).val().length) {
			$(this).val(this.defaultValue);
			$(this).css({color: '#999999'});
		}
	});

	return this;
};

function BindThumbnails(content) {
	/*$('.thumbnail').unbind('click');

	$('.thumbnail').click(function() {
		var image_src = $(this).find('img').attr('src');
		$('.slide_content div').html('<img src="' + image_src + '" />');
		$('.slide_container').slideDown();
		$.scrollTo($('.slide_content'), 500, {offset: -10});
		return false;
	});*/

	content.find('.thumbnail').lightBox({
		imageLoading: '/img/lightbox/lightbox-ico-loading.gif',
		imageBtnClose: '/img/lightbox/lightbox-btn-close.gif',
		imageBtnPrev: '/img/lightbox/lightbox-btn-prev.gif',
		imageBtnNext: '/img/lightbox/lightbox-btn-next.gif'
	});

	content.find(".report_cont").hide();
	content.find(".share_cont").hide();
	content.find(".feedback_cont").hide();

	content.find('.report_abuse.icon_flag').click(function() {
		$('.feedback_cont').hide();
		$('.share_cont').hide();

		var p = $(this).aPosition();
		var pWidth = $(this).outerWidth();
		var mWidth = $('.report_cont').outerWidth();
		var left = (p.left - 170) + 'px';
		var top = (p.top + 20) + 'px';

		if ($(this).parent().parent().hasClass('rating_text')) {
			$('.report_cont').find('input.content').val($(this).parent().parent().html());
		}

		$('.report_cont').css({top: top, left: left}).fadeIn("slow");

		return false;
	});

	content.find('.share_cont_click').click(function() {
		$('.feedback_cont').hide();
		$('.report_cont').hide();

		var p = $(this).aPosition();
		var pWidth = $(this).outerWidth();
		var mWidth = $('.share_cont').outerWidth();
		var left = (p.left - (mWidth / 2) + (pWidth / 2)) + 24 + 'px';
		var top = (p.top + 20) + 'px';

		$('.share_cont').css({top: top, left: left}).fadeIn("slow");

		return false;
	});

	content.find('.feedback_cont_click').click(function() {
		$('.share_cont').hide();
		$('.report_cont').hide();

		var p = $(this).aPosition();
		var pWidth = $(this).outerWidth();
		var mWidth = $('.share_cont').outerWidth();
		//var left = (p.left - mWidth + pWidth) + 16 + 'px';
		//var top = (p.top + 20) + 'px';
		var left = (p.left - 170) + 'px';
		var top = (p.top + 20) + 'px';
		
		$('.feedback_cont').css({top: top, left: left}).fadeIn("slow");

		return false;
	});

	content.find("a.feedback").click(function() { $(this).parent().parent().submit(); return false; });

	content.find('.feedback_cont .del_inline').click(function() {
		$('.feedback_cont').fadeOut("fast");
		return false;
	});

	content.find('.feedback_selection_click').click(function() {
		$('.feedback_selection').toggle();
		return false;
	});

	content.find('.share_cont .del_inline').click(function() {
		$('.share_cont').fadeOut("fast");
		return false;
	});

	content.find('.report_cont .del_inline').click(function() {
		$('.report_cont').fadeOut("fast");
		return false;
	});

	jQuery.fn.aPosition = function() {
		thisLeft = this.offset().left;
		thisTop = this.offset().top;
		thisParent = $('.maincont');
		parentLeft = thisParent.offset().left;
		parentTop = thisParent.offset().top;

		return {
			left: thisLeft - parentLeft,
			top: thisTop - parentTop
		}
	}
}