// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var jshover = function() {
	var sfEls = document.getElementById("menu").getElementsByTagName("li");
	for (var i = 0; i < sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			this.className += " jshover";
		}
		sfEls[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp(" jshover\\b"),
					"");
		}
	}
}

if (window.attachEvent)
	window.attachEvent("onload", jshover);

// if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent)
// && document.styleSheets && document.styleSheets[0]
// && document.styleSheets[0].addRule) {
// document.styleSheets[0].addRule('*', 'behavior: url(iepngfix.htc)');
// // Feel free to add rules for specific elements only, as above.
// // You have to call this once for each selector, like so:
// document.styleSheets[0].addRule('img', 'behavior: url(iepngfix.htc)');
// document.styleSheets[0].addRule('div', 'behavior: url(iepngfix.htc)');
// }

var shadowbox_conf = {
	animate : true,
	animateFade : true,
	animSequence : "wh",
	modal : false,
	overlayColor : "#000",
	overlayOpacity : 0.8,
	flashBgColor : "#000000",
	autoplayMovies : true,
	showMovieControls : true,
	slideshowDelay : 15,
	resizeDuration : 0.55,
	fadeDuration : 0.35,
	displayNav : true,
	continuous : false,
	displayCounter : true,
	counterType : "skip",
	counterLimit : 12,
	viewportPadding : 20,
	handleOversize : "resize",
	handleUnsupported : "link",
	initialHeight : 160,
	initialWidth : 320,
	enableKeys : true,
	players : ["img", "iframe"],
	language : "ru"

};

Shadowbox.init(shadowbox_conf);
var openShadowbox = function(content, player, title) {
	Shadowbox.open({
				content : content,
				player : player,
				title : title
			});
};
function openAdmin(url) {
	Shadowbox.open({
				content : url,
				player : "iframe",
				title : "Система администрирования",
				height : 700,
				width : 1024
			});

}

   // Корректное удаление записи    
   	
     function pageDestroy(pid) {
        $("#confirm").dialog({
            bgiframe: true,
            resizable: false,
            width: 400,
            open: function() { 
                $("#confirm_content").text( "Подтвердите необратимое удаление страницы." )
            },
            close: function() { 
                $("#confirm_content").text( "" )
            },
            height: 140,
            title: "Уничтожить текущую страницу?",
            modal: true,
            buttons: {
                'Да, я знаю что делаю!': function() {
                    document.location = "/pages/destroy/"+pid
                },
                'Ой! Не надо!': function() {
                    $(this).dialog('destroy');
                }
            }
        });

        
     }

// После загрузки страницы

$(document).ready(function() {

	$(".back").click(function() {
				history.back();
				return false;
			});

	/** Корректировка под ie */
	jQuery.each(jQuery.browser, function(i) {
				if ($.browser.msie) {
					$("#contentonwhite").css("overflow", "auto");
					$("#contentonwhite").css("overflow-x", "hidden");
					$("#restlogo").css("margin-right", "0px");

				}
			})

	// Переключение типов подписки
	$('#formEmail').hide();
	$('#goSMS').toggle();

	$('#goEmail a').click(function() {
				$('#formEmail').show();
				$('#formSMS').hide();
				$('#goEmail').toggle();
				$('#goSMS').toggle();
				return false;
			});
	$('#goSMS a').click(function() {
				$('#formEmail').hide();
				$('#formSMS').show();
				$('#goSMS').toggle();
				$('#goEmail').toggle();
				return false;
			});
	// Скролинг при больших простынях

	if ($("#contentonwhite").height() > 1200) {
		$("#contentonwhite").css("height", "600px");
	}

	// Правка PNG для IE

	$(document).pngFix();

	// Отладка старого Lightbox
	var myTimer = {};

	$('#contentonwhite img').click(function() {

				myTimer = $.timer(3000, function() {

					// Display hello message when timer goes off
					// alert('A Delayed Hello!');
					//$('#sb-wrapper').css("height", "100px");
					//$('#sb-wrapper').css("width", "100px")

						// Optional function to call when timer is
						// canceled
					}, function() {

						// Display new message when canceled
						alert('Hello Message Canceled!');

					});

			})

	// Кривая отладка отображения страницы about

	if (window.location.href == "http://rs.lakehouse.ru/about"
			|| window.location.href == "http://rs.lakehouse.ru/about/info") {

		$("#contentonwhite").css("height", "auto");
	}

	// The Ring
    
    // Стандартное окошко радостных сообщений
    if ($("#jqmessage").text().length > 2) {

        $("#jqmessage ").dialog({
                    modal : true,
                    width : 300,
                    buttons : {
                        Ok : function() {
                            $(this).dialog('close');
                        }
                    }

                })
    }
    
	// Большое окошко для всего
	$("#dialog").dialog({
				modal : true,
				autoOpen : false,
				width : 200,
				position : 'center'

			})

	$(document).bind('keydown', 'alt+a', function() {

				$("#dialog #dialog_content").load("/login", function() {
							$("#dialog").dialog('open');
							$("#dialog").dialog('option', 'title','Вход');
						});

			});
            
     

}); // ready
