﻿var clicked = 0;
var url = window.location.href;
if ( url.match(/\?s=[^\&]+/) ) {
	var clicked2 = 1;
} else {
	var clicked2 = 0;
}

function ClearSearch(it) {
	if (clicked2 == 0) {
		it.value = '';
		clicked2 = 1;
	}
	return true;
}

function getBrowserInfo() {
    var t,v = undefined;
    if (window.opera) t = 'Opera';
    else if (document.all) {
        t = 'IE';
        var nv = navigator.appVersion;
        var s = nv.indexOf('MSIE')+5;
        v = nv.substring(s,s+1);
    }
    else if (navigator.appName) t = 'Netscape';
    return {type:t,version:v};
}
 
function bookmark(a) { 
  title=document.title; 
  url=document.location; 
  try { 
    // Internet Explorer 
    window.external.AddFavorite(url, title); 
  } 
  catch (e) { 
    try { 
      // Mozilla 
      window.sidebar.addPanel(title, url, ""); 
    } 
    catch (e) { 
      // Opera 
      if (typeof(opera)=="object") { 
        a.rel="sidebar"; 
        a.title=title; 
        a.url=url; 
        return true; 
      } else { 
        // Unknown 
        alert('Нажмите Ctrl+D чтобы добавить страницу в закладки'); 
      } 
    } 
  } 
  return false; 
} 

function checkForm() {
    if (clicked2==1) {
        xoff=false;
        if (xoff) xoff = (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3 )) || ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)));
            with (document.forms) {
                err_msg="";
                if (formsearch.s.value.length<2) err_msg=err_msg+"Вы не ввели ключевое слово";
            }
            if ((err_msg.length>1)&&(!xoff)) {
                alert(err_msg);
                return false;
            } else return true;
    } else {
        alert("Вы не ввели ключевое слово");
        return false;
    }
}


function overlay(onclick, o_class) {
    var htmlDiv = $('<div class="'+o_class+'" id="overlay" style="height: '+$('body').height()+'px;" onclick="'+onclick+'">');
	var htmlImg = $('<img alt="" src="'+__TMPLPATH+'img/lightbox/run.gif">');
	htmlDiv.html(htmlImg).appendTo('body');
}

$(document).ready(function() {
    /*** logo animation ***/
	var method = 'easeOutElastic';
    var curlogo = 9;
    var nextlogo = 1;
    var nextnextlogo = 2;

	replaceLogos = function(){
		$('#logo-ico').attr('id','temp-logo-ico');
		$('#next-logo-ico').attr('id','logo-ico');
		$('#logo-ico').css('backgroundImage','url('+__TMPLPATH+'/img/logo/0'+nextlogo+'.png)');
		$('<div id="next-logo-ico" style="margin-left: -53px; background-image: url('+__TMPLPATH+'/img/logo/0'+nextnextlogo+'.png) "></div>').insertAfter('#logo');
		curlogo = nextlogo;
	};
	
	changeLogoIco = function (id,easing,time) {
		time2 = time*0.8;
		if(id==9){nextlogo=1;}else{nextlogo = id+1;}
		if(nextlogo==9){nextnextlogo=1;}else{nextnextlogo = nextlogo+1;}
		$('#logo-ico').stop().animate({ marginLeft: 52 }, { duration: time2 });
		$('#next-logo-ico').stop().animate({ marginLeft: 0 }, time, easing, replaceLogos );
	};

	changeLogoIco(curlogo,method,1000);
	logointerval = setInterval(function(){changeLogoIco(curlogo,method,1000);}, 7000);
	$('#logo').hover(function(){
		clearInterval(logointerval);
		changeLogoIco(curlogo,'easeOutExpo',500);
		logohoverinterval = setInterval(function(){changeLogoIco(curlogo,'easeOutExpo',500);}, 600);
	},function(){
		clearInterval(logohoverinterval);
		logointerval = setInterval(function(){changeLogoIco(curlogo,method,1000);}, 7000);
	});
	
	  

	
});

$(document).ready(function() {
	/***  tabs switcher ***/
	$(".switchers a").click(function() {
		var sw_class = $(this).parent().attr('class');
		var swc = sw_class.replace(' ','.');
		if (!$(this).hasClass('active')) {
			$('.'+swc+" a").removeClass('active');
			$(this).addClass('active');
			
			var content = $(this).attr('id');
			
			$('.'+swc).nextAll(".switchcontent").removeClass('active');
			$('#'+content+'_switch').addClass('active');
		}
		return false;
	});
});

$(document).ready(function() {
	
    /***  matchung selector ***/
    
    var hoverTo = undefined;
    
    $('#selection .choosen').click(function(){
        $(this).next('.variants').slideToggle('fast');
        $(this).parent().toggleClass('active');
    });
    
    $('#selection .variants').mouseleave(function(){
        moItem = $(this);
        moItem.slideUp('fast');
        moItem.parent().removeClass('active');
    });
    
    $('#selection .variants a').click(function(){
        $(this).parent().parent().parent().find('.choosen').html('<div>'+$(this).html()+'</div>');
        $(this).parent().parent().slideUp('fast');
        $(this).parent().parent().parent().removeClass('active');
    });
    
});

var setFooter;

$(document).ready(function() {
	
	setFooter = function () {
		if ($(window).height()>$('body').height()) {
			$('#main').css('height',$('#main').height()+$(window).height()-$('body').height());
		} else {
			$('#main').css('height','auto');
		}
	};	
	setFooter();
	
	$(window).resize(function(){
		setFooter();
	});
    
});


