function createBookmark(name) {
 we = window.external;
 if (!we) { return true; }
 else {
 we.addFavorite('http://slogen.ru/', name);
 return false;
 }
}

function trim11 (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}
function highlight(field) {
        field.focus();
        field.select();
}
function friend() {
	$("#fr").slideToggle("fast");
}
function email() {
	$("#send1").slideToggle("fast");
	$("#send2").slideToggle("fast");
if (document.getElementById('send1').style.display=='') {
document.getElementById('slogan2').focus();
document.getElementById('slogan2').select();
} 
}

function email2() {
document.getElementById('send4').style.display='none';
document.getElementById('send2').style.display='';
document.getElementById('slogan2').value='';
document.getElementById('slogan2').focus();
document.getElementById('slogan2').select();
}

function bookmarks() {
	$("#bkmks").slideToggle("fast");
}
function howto() {
	$("#how1").slideToggle("fast");
	$("#how2").slideToggle("fast");
}
function naprimer(n) {
$("#nap1").slideToggle("fast");
$("#slogan").val(n);
document.getElementById('slogan').focus();
}
function str_replace ( search, replace, subject ) {
    if(!(replace instanceof Array)){
        replace=new Array(replace);
        if(search instanceof Array){
            while(search.length>replace.length){
                replace[replace.length]=replace[0];
            }
        }
    }
    if(!(search instanceof Array))search=new Array(search);
    while(search.length>replace.length){
        replace[replace.length]='';
    }
    if(subject instanceof Array){
        for(k in subject){
            subject[k]=str_replace(search,replace,subject[k]);
        }
        return subject;
    }
    for(var k=0; k<search.length; k++){
        var i = subject.indexOf(search[k]);
        while(i>-1){
            subject = subject.replace(search[k], replace[k]);
            i = subject.indexOf(search[k],i);
        }
    } 
    return subject;
}

$(document).ready(function () {
var $panels = $('#slider .scrollContainer > div');
var $container = $('#slider .scrollContainer');
var horizontal = true;
if (horizontal) {
  $panels.css({
    'float' : 'left',
    'position' : 'relative'
  });
  $container.css('width', $panels[0].offsetWidth * $panels.length);
}
var $scroll = $('#slider .scroll').css('overflow', 'hidden');
$scroll
  .before('<img class="scrollButtons left" src="img/scroll-left.gif" />')
  .after('<img class="scrollButtons right" src="img/scroll-right.gif" />');
function selectNav() {
  $(this)
    .parents('ul:first')
      .find('a')
        .removeClass('selected')
      .end()
    .end()
    .addClass('selected');
}
$('#slider .navigation').find('a').click(selectNav);
function trigger(data) {
  var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
  selectNav.call(el);
}
if (window.location.hash) {
  trigger({ id : window.location.hash.substr(1) });
} else {
  $('ul.navigation a:first').click();
}
var offset = parseInt((horizontal ? 
  $container.css('paddingTop') : 
  $container.css('paddingLeft')) 
  || 0) * -1;
var scrollOptions = {
  target: $scroll, 
  items: $panels,
  navigation: '.navigation a',
  prev: 'img.left', 
  next: 'img.right',
  axis: 'xy',
  onAfter: trigger,
  offset: offset,
  duration: 300,
  easing: 'swing'
};
$('#slider').serialScroll(scrollOptions);
$.localScroll(scrollOptions);
scrollOptions.duration = 1;
$.localScroll.hash(scrollOptions);
});

function getCookie2( name ) {
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
        return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ';', len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}
function setCookie2( name, value, expires, path, domain, secure ) {
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ) {
        expires = expires * 1000 * 60 * 60 * 24 * 365;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name+'='+escape( value ) +
        ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
        ( ( path ) ? ';path=' + path : '' ) +
        ( ( domain ) ? ';domain=' + domain : '' ) +
        ( ( secure ) ? ';secure' : '' );
}
function deleteCookie( name, path, domain ) {
    if ( getCookie2( name ) ) document.cookie = name + '=' +
            ( ( path ) ? ';path=' + path : '') +
            ( ( domain ) ? ';domain=' + domain : '' ) +
            ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
function toggle1 (tank) {
	var state = document.getElementById(tank+'1').style.display;
	if (state == 'none') deleteCookie('no'+tank, '/'); else setCookie2('no'+tank, '1', 1, '/');
	$("#"+tank+"1").toggle("medium");
	$("#"+tank+"2").toggle("medium");
}

function keycheck(e) {
var keynum;
if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
//13
if (keynum==13) sendslogan();
}
function sendslogan() {
var slogan = $("#slogan").val();
if (slogan) {
$.post('http://'+host1+'/server.php',{slogan: slogan, nocache: nocache},handleslogan);
$("#d1").hide();
$("#d2").hide();
$("#d3").show();
} else alert('Вы не ввели слово');
}
function handleslogan(report) {
var text = $("comment", report).text();
var enc = $("comment", report).attr("encoded");
var slogan = $("comment", report).attr("slogan");
setTimeout("showslogan('"+text+"','"+enc+"','"+slogan+"')",300);
}
function showslogan(text,enc,slogan) {
$("#d1").show();
$("#d2").show();
$("#d3").hide();
$("#d1").html(text);
$("#nap1").html('<a title="Ссылка на слоганы с Вашим словом, нажмите сюда, чтобы скопировать её адрес в буфер обмена" href="#" onclick="prompt(\'Постоянная ссылка на слоганы с этим словом:\',\'http://'+host1+'/s/'+slogan+'\'); return false" class="link1">http://'+host1+'/s/'+slogan+'</a> (<a title="Перейти по ссылке" target=_blank class="link3" href="s/'+slogan+'">&rarr;</a>)');
$("#nap1").show();
document.getElementById('slogan').focus();
}
function sendslogan2() {
var slogan = $("#slogan2").val();
slogan = trim11(slogan);
if (slogan) {
$.post('http://'+host1+'/server.php',{slogan2: slogan},handleslogan2);
$("#send2").hide();
$("#send3").show();
} else alert('Слоган не введён');
}
function handleslogan2() {
$("#send3").hide();
$("#send4_text").html('Спасибо за участие в развитии проекта!');
$("#send4").show();
}