﻿$(document).ready(function() {

	if($.browser.opera)
	{
		$('.imagebutton').mouseover(function(){
			window.status = $(this).find('img').attr('alt');
		});
		$('.imagebutton').mouseout(function(){
			window.status = '';
		})
	}
	
	$('a[rel="external"]').click(function(){
		this.target = "_blank";
	});

	var txtCloseNoticeLink = Array("Скрыть объявление!", "Показать объявление!");
	var lnkCloseNoticeLink = $(".notice a.close");
	var boxNoticeContent = $(".notice .content");

	if(lnkCloseNoticeLink.length){
		var showNotice = getCookie("showNotice");
		if(showNotice) {
			if(showNotice == "yes") {
				boxNoticeContent.show();
				lnkCloseNoticeLink.text(txtCloseNoticeLink[0]);
			}
			else {
				boxNoticeContent.hide();
				lnkCloseNoticeLink.text(txtCloseNoticeLink[1]);
			}
		}
		lnkCloseNoticeLink.click(function(){
			if(boxNoticeContent.is(":visible")) {
				boxNoticeContent.slideUp();
				lnkCloseNoticeLink.text(txtCloseNoticeLink[1]);
				setCookie("showNotice", "no");
			}
			else {
				boxNoticeContent.slideDown();
				lnkCloseNoticeLink.text(txtCloseNoticeLink[0])
				setCookie("showNotice", "yes");
			}
			return false;
		})
	}

	//спойлер
	$('div.spoiler-body img').each(function() {
		$(this).attr({
			alt: $(this).attr('src'),
			src: 'clear.gif'
		});
	});
	$('div.spoiler-head').live("click", function() {
		$(this).toggleClass('unfolded');
		var c = $(this).parent().children('div.spoiler-body');
		c.find('img').each(function() {
			$(this).attr('src', $(this).attr('alt'));
		});
		c.is(':visible') ? c.hide('fast') : c.show('fast');
	});
	
});

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
