﻿$(document).ready(
function() {
    //для каждого li в ul-ах для FAQ
    // hide all div from li
    $("ul.revealingText li").find("div").hide();
    //bind click function for each li
    $("ul.revealingText li").bind("click",
  function() {
      if (!$(this).hasClass("active")) {
          // collapse prev activ element 
          $("ul.revealingText li.active").find("div").slideUp("slow");
          // remove class prev activ element 
          $("ul.revealingText li.active").removeClass("active");
          //expand current element
          $(this).addClass('active');
          $("ul.revealingText li.active").find("div").slideDown("slow");
      } else {
          $(this).find("div").slideUp("slow");
          $(this).removeClass("active");
      }

  }
);



    //главная страница
    $.each($("div.mainMenu"),
function() {
    var imgs = $(this).find("img");
    if (imgs.length > 0) {
        //old solution
        // num = $.random(imgs.length);

        //index block's of imgs 
        var y = $("div.mainMenu").index($(this));
        // read from cooks prev value
        num = readCookie('cookie' + y);
        // if exist when create list of imags index != num
        if (num) {
            var n = new Array();
            var d = 0;
            for (m = 0; m < imgs.length; m++) {
                if (m != num) {
                    n[d] = m;
                    d++;
                }
            }
            // generate new index
            k = Math.floor((imgs.length - 1) * Math.random());
            num = n[k];
        }
        else {
            num = Math.floor(imgs.length * Math.random());
        }
        // save new index in cooks
        createCookie('cookie' + y, num, 7);


        imgs.filter(":not(:eq(" + num + "))").hide();
        var img = imgs.filter(":eq(" + num + ")");
        img.show();
        var src = img.attr("src");
        var bw_src = src.toLowerCase().replace(".jpg", "_bw.jpg");
        var tmp = new Image();
        tmp.src = bw_src;
        $(this).bind("mouseover", function() {
            img.attr("src", bw_src);
        });
        $(this).bind("mouseout", function() {
            img.attr("src", src);
        });
    }
}
);
}
);


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


