﻿$(document).ready(function () {
	$("input:submit").button();
	$("input:button").button();
	$("button").button();
	$("a.button").button();
	$("a.fancy-image").fancybox({ 'type': 'image', 'titlePosition': 'over' });
});

function AddToFavorites(anchor, unsupportedErrorText) {
	var url = anchor.href;
	var title = anchor.title;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url, "");
	} else if (window.external && !window.chrome) { // IE Favorite
		window.external.AddFavorite(url, title);
	} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
		alert(unsupportedErrorText);
	}
}

function SetAsHomepage(anchor, unsupportedErrorText) {
	if (document.all) {
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage(location.href);
	} else alert(unsupportedErrorText);
}

function AttachHtmlEditor(webroot, textAreaID, showUploadButton, cultureName) {
	$('textarea#' + textAreaID).tinymce({
		// Location of TinyMCE script
		script_url: webroot + '/Scripts/tiny_mce/tiny_mce.js',

		// General options
		theme: "advanced",
		mode: "textareas",
		language: cultureName != null && cultureName == "ru-RU" ? "ru" : "uk",
		plugins: "pagebreak,style,table,advhr,advimage,advlink,emotions,inlinepopups,preview,media,searchreplace,print,contextmenu,paste,noneditable,visualchars,nonbreaking,advlist",

		// Theme options
		theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,forecolor,backcolor",
		theme_advanced_buttons3: showUploadButton ? "removeformat,|,link,unlink,anchor,|,advhr,nonbreaking,charmap,emotions,image,media,uploadmedia,|,print,cleanup,help,code,preview" : "removeformat,|,link,unlink,anchor,|,advhr,nonbreaking,charmap,emotions,image,media,|,print,cleanup,help,code,preview",
		theme_advanced_buttons4: "tablecontrols,|,styleselect",
		theme_advanced_toolbar_location: "top",
		theme_advanced_toolbar_align: "left",
		theme_advanced_statusbar_location: "bottom",
		theme_advanced_resizing: false,
		relative_urls: false,
		remove_script_host: false,
		width: "484px",
		height: "500px",
		content_css: webroot + "/Content/Site-20101221.css",
		setup: function (ed) {
			ed.addButton('uploadmedia', {
				title: cultureName != null && cultureName == "ru-RU" ? 'Загрузить медиа файл' : 'Завантажити медіа файл',
				image: webroot + '/Scripts/tiny_mce/themes/advanced/img/UploadIcon.png',
				onclick: function () {
					ed.focus();
					ed.execCommand('mceInsertContent', false, '%MEDIA%');
					parent.InsertTinyMceImage(textAreaID);
				}
			});
		}
	});
}
