FilippaK = function(){};
FilippaK.CloseElements = null;
FilippaK.RemoveElements = null;
FilippaK.IFrame = null;

$(document).ready( 
	function()
	{
		// Enable cross sub domain scripting
		document.domain = "filippa-k.com";
		setTimeout(function(){Init();}, 10);
	}
);

/// <summary>
///	Initiates the carousels when the browser is ready
/// </summary>
function Init()
{
	var element = document.getElementById(iframeId);
	try
	{
		var foundFilippaK = element.contentWindow != null;
		if(foundFilippaK)
		{
			foundFilippaK =  element.contentWindow.FilippaK != null;
		}
		
//		if(!foundFilippaK)
//		{
//			foundFilippaK = element.contentWindow != null && element.contentWindow.FilippaK != null;
//			
			if(!foundFilippaK)
			{
				setTimeout(function(){ Init(); }, 250);
				return;
			}
//		}
	}
	catch(e)
	{
		setTimeout(function(){ Init(); }, 250);
		return;
	}

	FilippaK.IFrame = element.contentWindow;

	element.contentWindow.FilippaK.ParentDocument = window;
	element.contentWindow.FilippaK.IsParentForm = true;

	var width = $(window).width();
	var docHeight = $(document).height();
	var winHeight = $(window).height();
	var theHeight = winHeight;
	if(docHeight > winHeight)
		theHeight = docHeight;
	
	element.contentWindow.FilippaK.Settings.ParentWindow = {"Width":width, "Height":theHeight, "WinHeight":winHeight};;
	element.contentWindow.FilippaK.Init();
	

		
}

/// <summary>
///	Creates spcified element in the dummy container
/// </summary>
function Create(element)
{
	var e = $(element);
	$("#dummy").append(e);
	return e;
}

/// <summary>
///	Creates spcified element in the dummy container
/// </summary>
function Clone(target, id)
{
	$(id).clone().appendTo(target);
}

/// <summary>
///	Appends specified element in specified element or in the dummy container
/// </summary>
function Append(p1, p2)
{
	if(p2 == null)
		$("#dummy").append(p1);
	else
		$(p1).append($(p2));
}

function Prepend(p1, p2)
{
	$(p1).prepend($(p2));
}

/// <summary>
///	Styles spcified element with provided array of css styles
/// </summary>
function Style(id, styles)
{
	$(id).css(styles);
}

function Width(id)
{
	return $(id).width();
}

function Height(id)
{
	return $(id).height();
}

/// <summary>
///	Puts provided text in specified element
/// </summary>
function Text(id, text)
{
	$(id).text(text);
}

/// <summary>
///	Puts provided html in specified element
/// </summary>
function Html(id, html)
{
	$(id).html(html);
}

/// <summary>
///	Gets or set specified attribute on specified element
/// </summary>
function Attribute(id, name, value)
{
	if(value != null)
		$(id).attr(name, value);
	else
		return $(id).attr(name);
}

/// <summary>
///	Removes specified element
/// </summary>
function Remove(id)
{
	$(id).remove();
}

/// <summary>
///	Fades specified element to specified opacity in specified speed
/// </summary>
function FadeTo(id, speed, opacity)
{
	$(id).fadeTo(speed, opacity);
}

/// <summary>
///	Fades out specified element to specified opacity in specified speed, calling specified function or removing element
/// </summary>
function FadeOut(id, speed, p1)
{
	if(typeof(p1) == "function"){
		$(id).fadeOut(speed, p1);
	}
	else if(p1 == true){
		$(id).fadeOut(speed, function(){ $(id).remove(); });
	}
	else{
		$(id).fadeOut(speed);
	}
}

/// <summary>
///	Binds a click event on provided elements (e), click removes provided elements (t)
/// </summary>
function BindClose(e, t)
{
	FilippaK.CloseElements = e;
	FilippaK.RemoveElements = t;
	
	for(var i = 0; i < FilippaK.CloseElements.length; i++)
	{
		$(FilippaK.CloseElements[i]).click( 
			function()
			{
				// Hide navbuttons
				FilippaK.IFrame.FilippaK.ShowNavButtons();
				
				for(var j = 0; j < FilippaK.RemoveElements.length; j++)
				{
					var id = FilippaK.RemoveElements[j];
					FadeOut(id, 250, true);
				}
			}
		);
	}
}

function Animate(id, params, duration )
{
	$(id).animate( params, duration );
}

/// <summary>
///	Binds provided funktion to the click event on specified element
/// </summary>
function BindOnClick(id, func)
{
	$(id).click(func);
}

/// <summary>
///	Binds provided funktion to the click event on specified element
/// </summary>
function BindOnClickFind(id, target, func)
{
	$(id).find(target).each(function(){ $(this).click(func); });
}

/// <summary>
///	Load a new url
/// </summary>
function LoadUrl(url)
{
	window.location = url;
}

function GetCurrentUrl()
{
	return window.location;
}

function IframeHeight(height)
{
	$("#" + iframeId).css("height", height);
}