﻿/* JavaScript Core 1.0 */
var _=function( id ){return new _.fn.init( id )}
_.fn = _.prototype = {
    $:null,
    isS:function(){return (this.$.style.display != 'none')},//Is Show
	h:function(){this.$.style.display = 'none';return this},//Hide
	s:function(){this.$.style.display = '';return this},//Show
	s2:function(){this.$.style.display = 'block';return this},//Show
	c:function(n){if(n==null)return this.$.className;else this.$.className = n;return this},//Class
	t:function(t){if(!t)return this.$.innerHTML;else this.$.innerHTML = t;return this},//HTML
	v:function(vel){if(vel==null)return this.$.value;else this.$.value = vel;return this},//Value
	a:function(n,v){if(!v)return this.$.getAttribute(n);else this.$.setAttribute(n,v);return this},//Attribute
	tn:function(n){return this.$.getElementsByTagName(n)}, // Get Element by TagName
	p:function(){return new _.fn.init( this.$.parentNode )},
	init:function(id){if(typeof id == "string")this.$ = document.getElementById(id); else this.$ = id}
}
_.fn.init.prototype = _.fn;

_.tout = function(e,i){
	e.style.zIndex = 10;
	_('Span'+i).h()
}

_.tover = function(e,i){
	e.style.zIndex = 1000000;
	_('Span'+i).s2()
}


/*ajax*/
_.ajaxObj = null;
_.ajaxQueue = new Array();
_.get = function(url,func,f) {
    if(!f) _.ajaxQueue.push({u:url,f:func});
    if(_.ajaxObj!=null && !f)return;
    if (window.XMLHttpRequest){_.ajaxObj = new XMLHttpRequest()} else if (window.ActiveXObject) {_.ajaxObj = new ActiveXObject("Microsoft.XMLHTTP")}
    _.ajaxObj.onreadystatechange = _.got;
    _.ajaxObj.open("GET", url, true);
    _.ajaxObj.send(null);
}
_.got = function() {
  if (_.ajaxObj.readyState == 4) {
      if (_.ajaxObj.status == 200) {
	     if(_.ajaxQueue[0].f!=null)
		    _.ajaxQueue[0].f(_.ajaxObj.responseText)
      }
      _.ajaxQueue.splice(0, 1);
      if(_.ajaxQueue.length>0){
	    _.get(_.ajaxQueue[0].u,_.ajaxQueue[0].f,true);
      }else{
	    _.ajaxObj = null
      }
  }
}
/*--end ajax*/
_.url = function(u){window.location.href = u}

_.qs = function(name){
    var val = window.location.querystring[name];
    if(val==null||val=='')
        val = '0';
    var filter = /^\d*$/i
    if(!filter.test(val))
        val = '0';
    return eval(val)
}
_.qsStr = function(name){
	var val = window.location.querystring[name];
    if(val==null||val=='')
        return '';
    else
		return decodeURI(val.replace(/\+/g,"%20"));
}

_.wnd = function(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen,left,top) {
	var int_windowLeft = (left==null)?(screen.width - a_int_windowWidth) / 2:left;
	var int_windowTop = (top==null)?(screen.height - a_int_windowHeight) / 2:top;
	var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=no,menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
	var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
	if (parseInt(navigator.appVersion) >= 4) {
		obj_window.window.focus();
	}
	return false;
}


// Core End
window.location.querystring = (function() {   
    var result = {};   
    var querystring = window.location.search;   
    if (!querystring)   
        return result;   
    var pairs = querystring.substring(1).split("&");   
    var splitPair;   
    for (var i = 0; i < pairs.length; i++) {   
        splitPair = pairs[i].split("=");   
        result[splitPair[0]] = splitPair[1];
    }   
    return result;   
})(); 

var __f = {
	pos:0,
	run:true,
	mio:function(e,d,pos){ // Main Item Over
		__f.run = false
		__f.miturn(e,d)
		__f.pos = pos
	},
	miout:function(){ // Main Item Over
		__f.run = true
	},
	miturn:function(e,d){ // Main Item Over
		var i = _(e.id+(d!=null?d:''));
		_('mild').$.href=_('mil').$.href=i.$.href;

		if(_('playvideo').$!=null)
			_('playvideo').$.href=_('mil').$.href=i.$.href;
			
		if(i.$.href.indexOf("video")>0){
			_('mild').$.onclick = _('mil').$.onclick = function(){return __f.online(this)}
		}else{
			_('mild').$.onclick = _('mil').$.onclick = function(){}
		}
		_('mild').t(i.t())
		_('mili').$.title = _('mili').$.alt = i.t();
		_('mili').$.src=_(i.$.id+'i').$.src.replace('133x97_','')
	},
	photo:function(e){return _.wnd(e.href, 'photo_popup'+ranVal(), 630, 493, 1, 0, 0, 0, 0, 1, 0)},
	video:function(e){return _.wnd(e.href, 'video_popup'+ranVal(), 433, 394, 1, 0, 0, 0, 0, 1, 0)},
	archive:function(filename){_.wnd('http://basket.fm/videostream/archive.aspx?url='+filename, 'filename_'+ranVal(), 433, 417, 1, 0, 0, 0, 0, 1, 0)},
	archive2:function(filename){_.wnd('http://basket.fm/videostream/video.aspx?p='+filename, 'filename_'+ranVal(), 600, 400, 1, 0, 0, 0, 0, 1, 0)},
	online:function(href){_.wnd(href, 'online_popup'+ranVal(), 433, 417, 1, 0, 0, 0, 0, 1, 0)},
	online2:function(href){_.wnd(href, 'online2_popup'+ranVal(), 700, 600, 1, 0, 0, 0, 0, 1, 0)},
	s:function(){_.url('/search.htm?text='+encodeURIComponent(_("st").v()));return false},
	cur:null,
	tOver:function(id){
		if(__f.cur!=id && __f.cur!=null){_(__f.cur).$.style.visibility='hidden'}
		__f.cur=id
		__f.t=true;_(id).$.style.visibility='visible'
	},
	tOut:function(id){
		__f.t=false;setTimeout('__f.tOutEnd(\"'+id+'\")',500)
	},
	tOutEnd:function(id){if(!__f.t)_(id).$.style.visibility='hidden'},
	t:false,
	th:function(e){},
	to:function(e){_(_(e).$.childNodes[0]).h().s();_(_(e).$.childNodes[2]).h().s()},
	liover:function(e){_(e).c('lihover')},
	liout:function(e){_(e).c('')}
}
function ranVal(){
	var t = Math.random();
	while(t<0.5){
		t = Math.random();
	}
	return Math.round(t*1000);
}
// Clock
var m_names = ["січня","лютого","березня","квітня","травня","червня","липня","серпня","вересня","жовтня","листопада","грудня"];
var daysOfWeek = ["Неділя","Понеділок","Вівторок","Середа","Четвер","П'ятниця","Субота"];
var sDT;
function _cInit(){_.get("/handler/serverTime.ashx",_fcInit);}
function _fcInit(data){
    eval("var sD =" + data);
    sDT = new Date();
    sDT.setFullYear(sD[0],sD[1]-1,sD[2]);
    sDT.setHours(sD[3],sD[4],sD[5]);
    _sC();
}
function _sC(){
    sDT.setSeconds(sDT.getSeconds()+1);
    var d = sDT;
    var cd = d.getDate();
    var cmth = d.getMonth();
    var y = d.getFullYear();
    var ch=d.getHours();
    var cm=d.getMinutes();
    if (ch==0) ch=12;
    if (cm<=9) cm='0'+cm;
    _('date').t( ch+':'+cm+', '+daysOfWeek[d.getDay()]+', '+cd+' '+m_names[cmth]+' '+y)
    setTimeout('_sC()',1000)
}


// Slide Show photo
var needSlide = false;
function slideClick(u){
	if(!needSlide){
		setTimeout("slide('"+u+"')",4000);
		_('fpbtn').c('fps')
	}else
		_('fpbtn').c('fpss')
	needSlide=!needSlide;
	return false
}
function slide(url){
	if(needSlide)
		_.url(url);
}

function subscribe(){
	_('err').c('err').h()
	if(_('email').v()==''){
		_('err').t('Введіть e-mail.').s()
	}else
		_.get('/handler/addemail.ashx?e='+_('email').v(),subscribeResult)
	return false
}
function subscribeResult(d){
	if(d==-1){
		_('err').t('Невірній e-mail.').s()
	}else if(d==0){
		_('err').t('Ви вже підписались на розсилку.').s()
	}else if(d==1){
		_('err').c('ok').t('Ви підписались на розсилку.').s()
		_('email').v('')
	}
}

var _log = {
	focusLogin:function(){
		_('l_tbLogin').c('loginInp w')
	},
	blurLogin:function(){
		if(_('l_tbLogin').v()==''){
			_('l_tbLogin').c('loginInp')
		}
	},
	focusPass:function(){
		_('l_tbPass').c('passInp w')
	},
	blurPass:function(){
		if(_('l_tbPass').v()==''){
			_('l_tbPass').c('passInp')
		}		
	}
}

function foreach(arr, f){
    for(var _i=0;_i<arr.length;_i++)
        f(arr[_i])
}

/*** Vote ***/
var _v = {
	switchDiv:function(n){
		var end = (n==null)?'':n;
		if(_('_vResult'+end).isS()){
			_('_vResult'+end).h()
			_('_vres'+end).h()
			_('_vbtn'+end).s()
			_('_vQuestino'+end).s()
		}else{
			_v.showRes(n)
		}
	},
	clickNew:function(n){
		var end = (n==null)?'':n;
		var checkedIDs = '';
		var checkedCount = 0;
		foreach( 
			_('_vQuestino'+end).tn('input'), 
			function(e){
				if(e.checked){
					checkedCount++;
					checkedIDs += (checkedIDs==''?'':',') + eval(e.value)
				}
			}
		)
		if(checkedCount!=3){
			_('voteError'+end).s().t('<br/>Необхідно вибрати 3 варіанти')
		}else{
			_.get('/handler/answerVote3.ashx?aid='+checkedIDs, function(n){ return function(data){_v._clickNNN(data,n)} }(end) );
		}
	},
	click:function(n){
		var end = (n==null)?'':n;
		var checkedID = 0;
		foreach( _('_vQuestino'+end).tn('input'), function(e){if(e.checked)checkedID=eval(e.value)})
		if(checkedID==0){
			_('voteError'+end).s().t('<br/>Не вибрано жодного варіанта')
		}else{
			if(end=='')
				_.get('/handler/answerVote'+end+'.ashx?aid='+checkedID,_v._click);
			else
				_.get('/handler/answerVote'+end+'.ashx?aid='+checkedID,_v._click2);
		}
	},
	_click:function(d){
		if(d.length==1){
			_('voteError').s().t('<br/>Ви вже голосували, Ваш голос не зараховано!')
		} else {
			_('voteBody').p().t(d)
			_v.showRes()
		}	
	},
	_click2:function(d){
		if(d.length==1){
			_('voteError2').s().t('<br/>Ви вже голосували, Ваш голос не зараховано!')
		} else {
			_('voteBody2').p().t(d)
			_v.showRes('2')
		}	
	},
	_clickNNN:function(d,n){
		if(d.length==1){
			_('voteError'+n).s().t('<br/>Ви вже голосували, Ваш голос не зараховано!')
		} else {
			_('voteBody'+n).p().t(d)
			_v.showRes(n)
		}	
	},	
	showRes:function(n){
		var end = (n==null)?'':n;
		_('_vResult'+end).s()
		_('_vres'+end).s2()
		_('_vbtn'+end).h()
		_('_vQuestino'+end).h()
	}
}
// Vote

