window.onload = setScreenClass; 
window.onresize = setScreenClass;

function setScreenClass() {
	var fmt = document.documentElement.clientWidth;
	var cls = (fmt<=1020) ? '1000' :
            (fmt>1000&&fmt<=1280) ? '1280' :
            (fmt>1280&&fmt<=1400) ? '1400' : '1600';
	
  $("#foto_1").attr('src','/files/size/IVECO-31_'+cls+'.jpg');
  $("#foto_2").attr('src','/files/size/IVECO-27-'+cls+'.jpg');
  $("#foto_3").attr('src','/files/size/OTOYOL_'+cls+'.jpg');
  $("#foto_4").attr('src','/files/size/Mitsu1_'+cls+'.jpg');
  
  if(cls == 1280) {
    $("#foto_1_img, #foto_2_img, #foto_4_img").empty();
    $("#foto_1_img").append("<a class=links onclick=\"window.open('/files/IVECO-31-4-big.jpg', 'null' ,'resizable=yes,toolbar=no, scrollbars=no, width=800, height=582')\" href='#iveco_31'><img height=73 alt='Заказ автобуса IVECO-31' width=100 border=0 vspace=5 src=\"/files/IVECO-31-4-small.jpg\" /></a>");
    $("#foto_2_img").append("<a class=links onclick=\"window.open('/files/IVECO-27-4-big.jpg', 'null' ,'resizable=yes,toolbar=no, scrollbars=no, width=800, height=600')\" href='#iveco_27'><img height=73 alt='Заказ автобуса IVECO-31' width=100 border=0 vspace=5 src=\"/files/IVECO-27-4-small.jpg\" /></a>");
  } else if(cls >= 1400) {
    $("#foto_1_img, #foto_2_img, #foto_4_img").empty();
    $("#foto_1_img").append("<a class=links onclick=\"window.open('/files/IVECO-31-4-big.jpg', 'null' ,'resizable=yes,toolbar=no, scrollbars=no, width=800, height=582')\" href='#iveco_31'><img height=73 alt='Заказ автобуса IVECO-31' width=100 border=0 vspace=5 src=\"/files/IVECO-31-4-small.jpg\" /></a><br><a class=links onclick=\"window.open('/files/IVECO-31-5-big.jpg', 'null' ,'resizable=yes,toolbar=no, scrollbars=no, width=800, height=501')\" href='#iveco_31'><img height=63 alt=\"Заказ автобуса IVECO-31\" width=100 border=0 src=\"/files/IVECO-31-5-small.jpg\" /></a>");
    $("#foto_2_img").append("<a class=links onclick=\"window.open('/files/IVECO-27-4-big.jpg', 'null' ,'resizable=yes,toolbar=no, scrollbars=no, width=800, height=600')\" href='#iveco_27'><img height=73 alt='Заказ автобуса IVECO-31' width=100 border=0 vspace=5 src=\"/files/IVECO-27-4-small.jpg\" /></a><br><a class=links onclick=\"window.open('/files/IVECO-27-5-big.jpg', 'null' ,'resizable=yes,toolbar=no, scrollbars=no, width=800, height=578')\" href='#iveco_27'><img height=73 alt='Заказ автобуса IVECO-31' width=100 border=0 vspace=5 src=\"/files/IVECO-27-5-small.jpg\" /></a>");
    $("#foto_4_img").append("<a class=links onclick=\"window.open('/files/MITSUBISHI.jpg', 'null' ,'resizable=yes,toolbar=no, scrollbars=no, width=800, height=572')\" href='#prestij'><img alt='Заказ автобуса Mitsubishi Prestij Deluxe' width=100 border=0 vspace=5 src=\"/files/MITSUBISHI_small.jpg\" /></a><br><a class=links onclick=\"window.open('/files/MITSUBISHI-5-big.jpg', 'null' ,'resizable=yes,toolbar=no, scrollbars=no, width=700, height=820')\" href='#prestij'><img alt='Заказ автобуса Mitsubishi Prestij Deluxe' width=100 border=0 vspace=5 src=\"/files/MITSUBISHI-5-small.jpg\" /></a>");
  } else $("#foto_1_img, #foto_2_img").empty();
  
  document.body.className=cls;
};







// обработкак куков
function setCookie(c_name,value,expiredays)
{
  var exdate = new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie = c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
  if(document.cookie.length > 0)
  {
    c_start = document.cookie.indexOf(c_name + "=");
    if(c_start != -1)
    { 
      c_start = c_start + c_name.length+1; 
      c_end = document.cookie.indexOf(";",c_start);
      if(c_end == -1)
        c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
} 

function checkCookie()
{
  username = getCookie('username');
  if(username != null && username != "")
  {
    alert('Welcome again '+username+'!');
  } else {
    username = prompt('Please enter your name:',"");
    if(username != null && username != "")
    {
      setCookie('username',username,365);
    } 
  }
}

// различные фунции

$(function() {
  // $('#sidemenu_1').tabs();
  $('#sidemenu_1').tabs({ fxFade: true, fxSpeed: 'fast' });
  $('#sidemenu_2').tabs({ fxFade: true, fxSpeed: 'fast' });
});

view_stats_field = getCookie('view_stats_field')-0;

$(document).ready(function(){
	$(".naviStats h3").eq(view_stats_field).addClass("active");
	$(".naviStats p").eq(view_stats_field).show();
	$(".naviStats h3").click(function() {
		$(this).next("p").toggle()
		.siblings("p:visible").toggle();
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});
});

function more_rub()
{
	$("#some_rub").hide();
	$("#all_rub").show();
}

// Быстрый переход
function fasrTrans()
{
	patch = document.getElementById('trans').value;
	top.location.href = patch;
}