function view_photo (imgSrc, imgWidth, imgHeight, imgTitle) {
 if (!imgWidth || !imgHeight) {
 imgWindow = window.open('', 'image', '');
 var html = '<html><head><title></title></head><body style="margin: 0; padding: 0;">' +
 '<img alt="' + imgTitle + '" src="' + imgSrc + '">' +
 '</body></html>';
 imgWindow.document.write(html);
 return;
 }

 var screenWidth = screen.availWidth;
 var screenHeight = screen.availHeight;
 var titleHeight = 30;
 if (imgTitle) { imgHeight = imgHeight + titleHeight; }
 var windowLeft, windowTop;
 if ((screenWidth - imgWidth) > 0) { windowLeft = (screenWidth - imgWidth) / 2 } else { windowLeft = 0; }
 if ((screenHeight - imgHeight) > 0) { windowTop = (screenHeight - imgHeight) / 2 } else { windowTop = 0; }
 var imgWindow = window.open('', 'image',
 'width=' + imgWidth + ', height=' + imgHeight +
 ', left=' + windowLeft + ', top=' + windowTop
 );
 var html = '<html><head><title>' + imgTitle + '</title></head><body style="margin: 0; padding: 0;">' +
 '<img alt="' + imgTitle + '" src="' + imgSrc + '">' +
 '<div style="heigth: ' + titleHeight + 'px; width: 100%; text-align: center; font: 10px Arial;">'+ imgTitle +'</div>' +
 '</body></html>';
 imgWindow.document.write(html);
 imgWindow.document.close();
 return;
}

$(window).load(init);
var idN = [];
var el=0;

function init(){
    cc = parseInt($.cookie('cid'));
    if (cid != cc) {
        $.cookie('page', '0', {
            expires: 0.002,
            path: '/'
        });
    }
    
    np = $.cookie('page');
    setpage(np > 0 ? np : 0);

    $("#pg" + np).css("font-size", "16px");
    $.cookie('cid', cid, {
        expires: 0.002,
        path: '/'
    });
}

function cont(page1,page2){
 	this.page1 = page1;
 	this.page2 = page2;
}

function setpage(n){
if (n != $.cookie('page')) $.cookie('page',n,{ expires: 0.002, path:'/'});
  el=n+1;
  $('#nav span').css("font-size","14px");
  $("#nav span:nth-child(" + el +")").attr("id","current");
        $(".page")
        .animate({color: "#000"}, {queue:true, duration:300 })
        .animate({color: "#FAFAFA"}, { queue:true, duration:250})
        .queue(function() {
                $("#page-1")
                .empty()
                .html(cArr[n].page1)
                $("#page-2")
                .empty()
                .html(cArr[n].page2)
                $(".page")
                .animate({color: "#FAFAFA"}, {queue:false, duration:250})
                .animate({color: "#000"}, {queue:true, duration:300})
         })
		 .queue(function(){
		 	$(".vote input").bind("click",checkVote)
			$("#check-votes").bind("click",checkVotes)
		 })
         .stop();
$('#current').css("font-size","16px")
.attr("id","pg"+n);
}


function PNG(element) {
if(/MSIE (5\.5|6).+Win/.test(navigator.userAgent)){
	var src;
	if(element.tagName=='img'){
		if(/\.png$/.test(element.src)){
			src=element.src;element.src="../images/emp.gif";
		}
	}else{
		src=element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
		if(src){
			src=src[1];element.runtimeStyle.backgroundImage="none";
  		}
	}
  if(src)element.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"',sizingMethod='crop')";
}
}

function checkVotes(){
    t = 0;
    if (vote_a.length > 0) {
        for (i = 0; i <= vote_a.length - 1; i++) {
            if (vote_a[i].replay_t =='') {
                alert('Вы дали ответы не все вопросы!');
                return 0;
            }
            if (vote_a[i].replay == vote_a[i].replay_t) {
                t++;
            }
        }
        if (t > 0 && t == vote_a.length) {
            alert("Тест пройден!")
        }
        else {
            alert("Правильных ответов: " + t + " Не правильных ответов: " + (vote_a.length - t));
        }
    }
}


function checkVote(){
    var replay_c = 0;
    var replay_true;
    for (i = 0; i <= vote_a.length - 1; i++) {
        name = "#vote-" + vote_a[i].id;
        $(name + " input").each(function(j){
            if (this.checked) {
                replay_c++;
                vote_a[i].replay_t = j+1;
                if (j == vote_a[i].replay) {
                    replay_true++
                }
                else {
                    replay_true--
                }
            }
        });
    }
}
