/*common.js*/
            function confirmLink(_title, _link) {
    if (confirm(_title)) {
        location.href = _link;
    }
}


function confirmSubmit(frm, _title) {
    if (confirm(_title)) {
        frm.submit();
    }
}


function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}


$(document).ready(function() {
    $(".close").click(function() {
        $(this).parents(".ajwin").hide();
    });
    $("#debugwin").hover(function() {
        $("#debugwin").css('height', '40%');
        $("#debugwin").fadeTo('fast', 1);
    }, function() {
        $("#debugwin").css('height', '5%');
        $("#debugwin").fadeTo('fast', .3);
    });
    $("#debugwin").dblclick(function() {
        $("#debugwin").hide();
    });
});

function show_message(dhref, w, h) {
    x = Math.round((screen.height / 2) - (h / 2));
    y = Math.round((screen.width / 2) - (w / 2));
    newWindow = window.open(dhref, "wMessage", "width=" + w + ",height=" + h +
    ",resizable=no,scrollbars=no,top=" +
    x +
    ",left=" +
    y);
    newWindow.focus();
}


function ajwin_hide(ajwin) {
    $('#' + ajwin).hide();
}


function inlinediv(obj, ddobj) {
    ajobj = $('#' + ddobj);
    ileft = Math.round((($(window).width() -
    $(ajobj).css('width').replace("px", ""))) /
    2);
    itop = Math.round((($(window).height() - $(ajobj).height()) / 2));
    $(ajobj).css("position", 'absolute');
    $(ajobj).css("top", itop + 'px');
    $(ajobj).css("left", ileft + 'px');
    $(ajobj).show();
}


function ajwin_show(obj, ajwin) {
    inlinediv(obj, ajwin);
}


/**
 * inpage Tabs
 */
function ClearPages() {
    for (var i = 0; i < tabpagescount; i++) {
        $('#page' + i).hide();
        $('#tab' + i).removeClass('selected');
    }
}


function SelectPage(i) {
    ClearPages();
    $('#page' + i).show();
    $('#tab' + i).addClass('selected');
}


function RecalcSelected(id, chname, formname) {
    checkboxes = document.forms[formname].elements[chname];
    if (!checkboxes) return;
    var items = checkboxes.length ? checkboxes : [checkboxes];
    ccount = 0;
    for (var i = 0; i < items.length; i++) {
        if (items[i].checked) {
            ccount++;
        }
    }
    hcc = document.getElementById("htcount" + id);
    hcc.innerHTML = '(' + ccount + ')';
}


function ShowHideHB(id, chname, formname) {
    obj = document.getElementById('ht' + id);
    ddobj = document.getElementById('hc' + id);
    ddobj.left = obj.left;
    ddobj.top = obj.top + 21;
    if (ddobj.style.display == "block") {
        ddobj.style.display = "none";
        if (document.getElementById("topBanner")) {
            document.getElementById("topBanner").style.visibility = 'visible';
        }
        RecalcSelected(id, chname + '[]', formname);
    }
    else {
        if (document.getElementById("topBanner")) {
            document.getElementById("topBanner").style.visibility = 'hidden';
        }
        ddobj.style.display = "block";
    }
}


function getCookie(name) {
    var elems = document.cookie.split(';');
    for (var i = 0; i < elems.length; i++) {
        var arr = elems[i].split('=');
        if (arr[0] == name) return arr[1];
    }
    return null;
}


function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

/*layout.js*/
            $(document).ready(function() {
    $("div#lt-top-links ul li:last").css("margin-right", '0');
});

$(document).ready(function() {
    $("a.dkid").each(function() {
        $(this).attr("target", '_blank');
    });
});
/*vote.js*/
            $(document).ready(function() {
	$(".vote_box .active span").live('click',function(event) {
		
		//event.preventDefault();
		var vote = $(this).attr("id").substr(4);
		sendvote(vote);
	})
	
	$(".get-discount").click(function(event) {
		
		event.preventDefault();
		
    	if ($(this).attr("clicked") == 1) {
    		
    		$(".get-discount").attr("clicked", 0);
    		$(".div_bonus_discount").slideUp();
    		$(".div_bonus_gift").slideUp();
    	}
    	else {
    		$(".get-discount").attr("clicked", 1);
    		$(".get-gift").attr("clicked", 0);
    		$(".div_bonus_gift").slideUp();
    		$(".div_bonus_discount").slideDown();
    		
        }
	});
	
	$(".get-gift").click(function(event) {
		
		event.preventDefault();
		
    	if ($(this).attr("clicked") == 1) {
    		
    		$(".get-gift").attr("clicked", 0);
    		$(".div_bonus_gift").slideUp();
    		$(".div_bonus_discount").slideUp();
    		
    	}
    	else {
    		$(".get-gift").attr("clicked", 1);
    		$(".get-discount").attr("clicked", 0);
    		$(".div_bonus_discount").css("background-position", "bottom");
    		$(".div_bonus_discount").slideUp();
    		$(".div_bonus_gift").slideDown();
    		
        }
	});
		
	
});


function sendvote(id) {
	
	var org_id = $('#org_id').html();
	var hashbox = $('.hashbox').html();
	var category = $('.category_box').html();
	
	$.post("index.php",{vote:id,org:org_id,h:hashbox,cat:category},function(data,textStatus){ 
		//обработкой текстового статуса  и указанием типа данных XML
		if(textStatus == 'success')
			{
			
			//alert("Полученные данные:"+data+", статус: "+textStatus);
			
			if(data == 'error')
	 		{
	 		$('.vote_info').html('Голосование разрешено <strong>один раз в сутки</strong>');
	 		$('.vote_bar').removeClass('active');
	 		}
	 	else if (data == 'ok')
	 		{
	 			$('.vote_info').html('<strong>Спасибо, ваш голос учтён</strong><br>Средний балл обновится в течении 2-х минут - <a href="http://premiakirov.ru/about/rules/" title="правила участия">правила участия</a>');
	 			var width = id * 23 + (id - 1) * 90 / 9;
	 			if(width > 311) width = 311;
	 			$('.vote_bar div').removeClass("vote_bar_back").addClass("sendvote").css('width',Math.floor(width) +'px');
	 			$('.vote_bar').removeClass('active');
	 		}
			 	return true;
			}
		else
			{
				//return false;
			}
		
		
		 },"html");
	//return false;
}

/*common.js*/
            $(document).ready(function(){
    prev = '1';
    $(".zebra").attr("border", 0);
    $(".zebra").attr("cellspacing", 0);
    $(".zebra").attr("cellpadding", 0);
    $(".zebra tr").each(function(event){
        $(this).hover(function(event){
            $(this).addClass("hover");
        }, function(){
            $(this).removeClass("hover");
        });
        $(this).click(function(){
            $(this).toggleClass("click");
        });
        if (prev == 1) {
            $(this).addClass("dark");
            prev = 0;
        }
        else {
            $(this).addClass("light");
            prev = 1;
        }
        
    });
});

$(document).ready(function(){
    $(".disabled").click(function(event){
        event.preventDefault();
    });
    
    $('.rounded div.ititle').hover(function(event){
        $(this).addClass("ihover");
    }, function(){
        $(this).removeClass("ihover");
    });
    
    $('.rounded div.ititle').click(function(event){
        frm = $(this).parents("div.rounded");
        $(frm).toggleClass("collapsed");
        fid = $(frm).attr("id");
        if ($(frm).hasClass("collapsed")) {
            SetCookieForNMinuts('collapsed_' + fid, 1, 100, '/');
        }
        else {
            SetCookieForNMinuts('collapsed_' + fid, 99, 100, '/');
        }
    });
});

$(document).ready(function(){
    $(".laureat-full .picture ul li img").css("cursor", 'pointer');
    $('.laureat-full .picture ul li img').fadeTo("fast", .7);
    $('.laureat-full .picture ul li img').hover(function(event){
        $(this).fadeTo("fast", 1);
    }, function(){
        $(this).fadeTo("fast", .7);
    });
    
    $('.laureat-full .picture ul li').click(function(event){
        event.preventDefault();
        $('.laureat-full .picture ul li').removeClass('selected');
        $(this).addClass("selected");
        $("#imainimage").attr("src", $(this).find("img").attr("longdesc"));
    });
});
  
$(document).ready(function(){
    if ($('.comments_form').hasClass("expanded")) {
        $('.comments_form form').show();
    }
    else {
        $('.comments_form form').hide();
    }
    $('.comments_title').css('cursor', 'pointer');
    $('.comments_title').css('border-bottom', '1px dashed #666');
    $('.comments_title').click(function(){
        $('.comments_form form').slideToggle("fast");
    });
});  
/*banner_loader.js*/
            $(document).ready(function(){
    $(".tblock .close").click(function(){
        $(this).parents(".tblock:first").hide("fast");
        var exp = new Date();
        var oneMinute = exp.getTime() + (60 * 1000 * 10);
        exp.setTime(oneMinute);
        setCookie('hide' + $(this).parents(".tblock:first").attr("id"), '1', exp, '/');
    });
});

var flInstalled = false;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if (plugin) {
    plugin = parseInt(plugin.description.substring(plugin.description.indexOf(".") -
    2)) >=
    6;
}
else 
    if (navigator.userAgent &&
    navigator.userAgent.indexOf("MSIE") >= 0 &&
    (navigator.userAgent.indexOf("Windows 95") >= 0 ||
    navigator.userAgent.indexOf("Windows 98") >= 0 ||
    navigator.userAgent.indexOf("Windows NT") >=
    0)) {
        document.write('<SCRIPT LANGUAGE=VBScript\> \n');
        document.write('on error resume next \n');
        document.write('plugin=( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))\n');
        document.write('</SCRIPT\> \n');
    }
if (plugin) {
    flInstalled = true;
}
else {
    flInstalled = false;
}

function fltxt(w, h, p, fv){
    return '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" WIDTH=' +
    w +
    ' HEIGHT=' +
    h +
    '> <PARAM NAME=movie VALUE="' +
    p +
    '"> <PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=high> <PARAM NAME=flashvars VALUE="' +
    fv +
    '"> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="' +
    p +
    '" menu=false quality=high bgcolor=#FFFFFF flashvars="' +
    fv +
    '" swLiveConnect=FALSE WIDTH=' +
    w +
    ' HEIGHT=' +
    h +
    ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>';
}

function LoadBanner(el, burl, w, h, bsrc, fl){
    if (fl) {
        $("#" + el).html(fltxt(w, h, bsrc, "nhref=" + burl));
    }
    else {
        $("#" + el).html('<a href="' + burl + '" target="_blank"><img src="' +
        bsrc +
        '" width="' +
        w +
        '" height="' +
        h +
        '" /></a>');
    }
}

/*jquery.countdown.js*/
            /*
 * Metadata - jQuery countdown plugin
 * http://alexmuz.ru/jquery-countdown/
 *
 * Copyright (c) 2009 Alexander Muzychenko
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

(function($) {
	$.fn.countdown = function (date, options) {
		options = $.extend({
			lang: {
				years:   ['год', 'года', 'лет'],
				months:  ['месяц', 'месяца', 'месяцев'],
				days:    ['день', 'дня', 'дней'],
				hours:   ['час', 'часа', 'часов'],
				minutes: ['минута', 'минуты', 'минут'],
				seconds: ['секунда', 'секунды', 'секунд'],
				plurar:  function(n) {
					return (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
				}
			}, 
			prefix: "Осталось: ", 
			finish: "Всё"			
		}, options);
		
		var timeDifference = function(begin, end) {
		    if (end < begin) {
			    return false;
		    }
		    var diff = {
		    	seconds: [end.getSeconds() - begin.getSeconds(), 60],
		    	minutes: [end.getMinutes() - begin.getMinutes(), 60],
		    	hours: [end.getHours() - begin.getHours(), 24],
		    	days: [end.getDate()  - begin.getDate(), new Date(begin.getYear(), begin.getMonth()+1, 0).getDate()]
		   // 	months: [end.getMonth() - begin.getMonth(), 12]
		    //	years: [end.getYear()  - begin.getYear(), 0]
		    };
		    var result = new Array();
		    var flag = false;
		    for (i in diff) {
		    	if (flag) {
		    		diff[i][0]--;
		    		flag = false;
		    	}    	
		    	if (diff[i][0] < 0) {
		    		flag = true;
		    		diff[i][0] += diff[i][1];
		    	}
		    	//if (!diff[i][0]) continue;
			    result.push('<div>' + diff[i][0] + '<span> ' + options.lang[i][options.lang.plurar(diff[i][0])] + '</span></div>');
		    }
		    return result.reverse().join(' ');
		};
		var elem = $(this);
		var timeUpdate = function () {
		    var s = timeDifference(new Date(), date);
		    if (s.length) {
		    	elem.html(options.prefix + '<br/>' + s);
		    } else {
		        clearInterval(timer);
		        elem.html(options.finish);
		    }		
		};
		timeUpdate();
		var timer = setInterval(timeUpdate, 1000);		
	};
})(jQuery);

