function myJS() {
	var tt=this;
	this.mainSrc=$('#mainimg').attr('src');
	$('.photoalbom img').mouseover(function(){ tt.myover(this) }).mouseout(function(){ tt.myout(this) });
	dd=$('.photoalbom a').get();
	for(i=0;i<dd.length;i++) {
		(new Image()).src=this.mainSrc.replace(/\/sysfiles\/\d+_\d+.\w+/,dd[i]).replace(/http:\/\/[^\/]+/,'');
	}
}
 
myJS.prototype.myover=function(el) {
	$('#mainimg').attr('src',this.mainSrc.replace(/\/sysfiles\/\d+_\d+.\w+/,$(el).parent().attr('href')));
}
 
myJS.prototype.myout=function(el) {
	$('#mainimg').attr('src',this.mainSrc);
}

function myCookie() {
}

myCookie.prototype.setMyCookie=function(names,sid) {
	document.cookie=names+'='+sid+"; path=/";
}

myCookie.prototype.getMyCookie=function(name) {
	var allCookie=document.cookie.split('; ');
	var count=allCookie.length;
	var ret='';
	for (i=0; i<count; i++) {
		now_cookie=allCookie[i].split('=');
		if (now_cookie[0]==name) ret=now_cookie[1];
	}
	return ret;
}

myCookie.prototype.getRandomInt=function(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

	


jQuery(document).ready(function() { 
	if(document.getElementById('mainimg')) var myjs=new myJS(); 
	$('.collectionsButton').toggle(function(){
			$('.collectionsItems').slideDown();
		},
		function(){
			$('.collectionsItems').slideUp();
		}
	);

	$('#call-btn').toggle(function(){
			$('.call-form').slideDown();
		},
		function(){
			$('.call-form').slideUp();
		}
	);	

	$('.search-catalog').toggle(function(){
			$('.searchcat').slideDown();
		},
		function(){
			$('.searchcat').slideUp();
		}
	);		
	//actiyaTimer();
	
});

function actiyaTimer() {
    var time=$('#timer-time').html();
    var tmp=time.split(':');
    var dec_h=0;
    var dec_m=0;
    var h=tmp[0];
    if(h.substr(0,1)=='0') h=h.substr(1);
    h=Number(h);
    var m=tmp[1];
    if(m.substr(0,1)=='0') m=m.substr(1);
    m=Number(m);
    var s=tmp[2];
    if(s.substr(0,1)=='0') s=s.substr(1);
    s=Number(s);
    s--;
    if(s<0) {
      s=59;
      dec_m=1;
    }
    if(dec_m) {
      m--;
      if(m<0) {
	m=59;
        dec_h=1;	
      }
    }
    if(dec_h) {
      h--;
      if(h<0) {
	$('#timer-time').html('00:00:00');
	return;
      }
    }
    $('#timer-time').html(formatChas(h)+':'+formatChas(m)+':'+formatChas(s));
    setTimeout(actiyaTimer, 1000);
}

function formatChas(t) {
	out=t;
	if (t<10) out='0'+t;
	out+='';
	return out;
}

function akciyaTimer(time) {
    this.time=time;
    var tmp=time.split(':');
    this.h=tmp[0];
    if(this.h.substr(0,1)=='0') this.h=this.h.substr(1);
    this.h=Number(this.h);
    this.m=tmp[1];
    if(this.m.substr(0,1)=='0') this.m=this.m.substr(1);
    this.m=Number(this.m);
    this.s=tmp[2];
    if(this.s.substr(0,1)=='0') this.s=this.s.substr(1);
    this.s=Number(this.s);
    this.animate();
}

akciyaTimer.prototype.animate=function() {
    var dec_h=0;
    var dec_m=0;
    var timer=0;
    this.s--;
    if(this.s<0) {
      this.s=59;
      dec_m=1;
    }
    if(dec_m) {
      this.m--;
      if(this.m<0) {
	this.m=59;
        dec_h=1;	
      }
    }
    if(dec_h) {
      this.h--;
      if(this.h<0) {
	this.s='0';
	this.h='0';
	this.m='0';
      }
    }
    this.renderTime();
}

akciyaTimer.prototype.renderTime=function() {
    var ts=formatChas(this.s);
    var tm=formatChas(this.m);
    var th=formatChas(this.h);
    var el=this;
    console.log(ts);
    var ts1=ts.substr(0,1);
    var ts2=ts.substr(1);
    var tm1=tm.substr(0,1);
    var tm2=tm.substr(1);
    var th1=th.substr(0,1);
    var th2=th.substr(1);
    $('.clock').html("<span class='clock"+th1+"'></span><span class='clock"+th2+"'></span><span class='clock-div'></span><span class='clock"+tm1+"'></span><span class='clock"+tm2+"'></span><span class='clock-div'></span><span class='clock"+ts1+"'></span><span class='clock"+ts2+"'></span>")
    setTimeout(function(){el.animate()}, 1000);
}
