/*
 * jQuery Backstretch
 * Version 1.2.3
 * http://srobbin.com/jquery-plugins/jquery-backstretch/
 *
 * Add a dynamically-resized background image to the page
 *
 * Copyright (c) 2011 Scott Robbin (srobbin.com)
 * Dual licensed under the MIT and GPL licenses.
*/
(function(a){a.backstretch=function(k,i,l){function m(c){try{g={left:0,top:0},d=e.width(),b=d/j,b>=e.height()?(h=(b-e.height())/2,f.centeredY&&a.extend(g,{top:"-"+h+"px"})):(b=e.height(),d=b*j,h=(d-e.width())/2,f.centeredX&&a.extend(g,{left:"-"+h+"px"})),a("#backstretch, #backstretch img").width(d).height(b).filter("img").css(g)}catch(o){}typeof c=="function"&&c()}var n={centeredX:!0,centeredY:!0,speed:0},c=a("#backstretch"),f=c.data("settings")||n;c.data("settings");var e="onorientationchange" in window?a(document):a(window),j,d,b,h,g;i&&typeof i=="object"&&a.extend(f,i);a(document).ready(function(){if(k){var b;c.length==0?c=a("<div />").attr("id","backstretch").css({left:0,top:0,position:"fixed",overflow:"hidden",zIndex:-999999,margin:0,padding:0,height:"100%",width:"100%"}):c.find("img").addClass("deleteable");b=a("<img />").css({position:"absolute",display:"none",margin:0,padding:0,border:"none",zIndex:-999999}).bind("load",function(b){var d=a(this),e;d.css({width:"auto",height:"auto"});e=this.width||a(b.target).width();b=this.height||a(b.target).height();j=e/b;m(function(){d.fadeIn(f.speed,function(){c.find(".deleteable").remove();typeof l=="function"&&l()})})}).appendTo(c);a("body #backstretch").length==0&&a("body").append(c);c.data("settings",f);b.attr("src",k);a(window).resize(m)}});return this}})(jQuery);

$(document).ready(function() {
	
	//$.backstretch("/frontend/themes/triton/core/layout/images/bg.jpg");

	resize();
		
	$(window).resize(function() {
		resize();
	});

	
	function resize()
	{
		if($(window).height() < $(document).height())
		{
			$('#sideWrapper').height($(document).height());
		}
		else
		{
			$('#sideWrapper').height('100%');
		}
	}

	// a-img problem
	$('.content a > img').parent().addClass('linkedImage');

	// p-img problem
	$('.content p img').each(function(i)
	{
		// get parent (p)
		var parent = $(this).parents('p').get(0);

		// copy of parent
		parentCopy = parent.clone();

		// get all images inside parent
		parentCopy.find('img').each(function()
		{
			if($(this).hasClass('alignLeft') || $(this).hasClass('alignRight'))
			{
				if($(this).parent('a').length) $(this).parent('a').remove();
				else $(this).remove();
			}
		});

		// no more content left = only images so we'll add a class to the container
		if(!parentCopy.html().replace(/\s*/g, '')) parent.addClass('floatedImage');
	});

	// enable the share-menu
	if($('.share').length > 0) $('.share').shareMenu();
});
