jQuery(function($) {
	var poll = $('.poll');
	if (poll.length) {
		$(poll).find('form').submit(function() {
			$.post($(this).attr('action'), $(this).serialize(), function(r) {
				if (r.error) return alert(r.error);
				$(poll).html(r.html);
			}, 'json');
			return false;
		});
	}

	var topnews = $('.s2.mainnew');
	if (topnews.length) {
		object = $(topnews).find('h3');
		var timeout;
		$(object).live('mouseover', function() {
			$(this).parent().find('#glanews').show(150);
		}).live('mouseout', function() {
			if (!timeout)
			timeout = setTimeout(function() {
				$(object).parent().find('#glanews').hide(150);
			}, 500);
		});

		$(topnews).find('#glanews').live('mouseover mouseout', function(event) {
			if (event.type == 'mouseover') {
				clearTimeout(timeout);
				timeout = null;
			} else if (event.type == 'mouseout') {
				$(topnews).find('h3').mouseout();
			}
		});
	}

	/*var hotnews = $('.hotnews');
	if (hotnews.length) {
		var hotblock = {
			idx: 0,
			items: hotnews.find('a'),
			timeout: 0,
			next: function() {
				this.idx++;
				if (this.idx >= this.items.length) {
					this.idx = 0;
				}
				clearTimeout(this.timeout);
				this.show(this.idx);
			},
			prev: function() {
				this.idx--;
				if (this.idx < 0) {
					this.idx = this.items.length - 1;
				}
				clearTimeout(this.timeout);
				this.show(this.idx);
			},
			show: function(idx) {
				$(this.items).hide();
				//$(this.items[idx]).show('slow');
				this.timeout = setTimeout(function() {
					hotblock.next();
				}, 5000);
			}
		};

		hotnews.find('.hotleft').click(function() {
			hotblock.prev();
		});
		hotnews.find('.hotright').click(function() {
			hotblock.next();
		});
		hotblock.show(0);
	}*/

	var login = $('.avt');
	if (login.length) {
		$(login).find('b:first').click(function() {
			$('.auth-popup').show();
		});

		$('.auth-popup .autohead a').click(function() {
			$('.auth-popup').hide();
		});

		/*$('#auth-popup form').submit(function() {
			$.post($(this).attr('action'), $(this).serialize(), function(r) {
				console.log(r);
				if (r.error) {
					return alert(r.error);
				}
				document.location.reload();
			});
			return false;
		});*/
	}

	$('#search').find('form').submit(function() {
		if ($(this).find('#query').val().length < 3) {
			return false;
		}
	});

	$('#search').find('.where span').live('click', function() {
		$('#search').find('.where .what').show();
	});

	$('#search').find('.what li').click(function() {
		img = $('#search').find('.where span img');
		$('#search').find('.where span').html($(this).html() + "<img alt='' src='/static/images/se3.gif'>"/*$(img).attr('outerHTML')*/);
		document.getElementById('where').value=$(this).attr('title');
		$(this).parent().parent().hide();
	});


$('#search_in').find('form').submit(function() {
		if ($(this).find('#query_in').val().length < 3) {
			return false;
		}
	});

	$('#search_in').find('.where span').live('click', function() {
		$('#search_in').find('.where .what').show();
	});

	$('#search_in').find('.what li').click(function() {
		img = $('#search_in').find('.where span img');
		$('#search_in').find('.where span').html($(this).html() + "<img alt='' src='/static/images/se3.gif'>"/*$(img).attr('outerHTML')*/);
		document.getElementById('where_in').value=$(this).attr('title');
		$(this).parent().parent().hide();
	});


$('.pop_n_mm').find('li').click(function() {
		
		
	});


        var current_n='za_segodnya';
	var tabs_n = $('.pop_n_mm');
	if (tabs_n.length) {;
		$(tabs_n).find('li').live('click', function() {
			$('#' + current_n).css('display','none');
			current_n = $(this).attr('rel');

			$(tabs_n).find('li').removeClass('onh');
			$(this).addClass('onh');
			$('#' + current_n).css('display','block');
		});
	}




	var tv = $('.tv2');
	if (tv.length) {
		$(tv).find('li').live('click', function() {
			id = $(this).attr('rel');
			var scrl_tmp=$('#onl_ch_list').attr('scrollLeft');
			var l_tmp=$('#onl-tv-left').css('display');
			var r_tmp=$('#onl-tv-right').css('display');
			//$(tv).load('/home/switchTv/channel/' + id);
			$.ajax({
                         url: '/home/switchTv/channel/' + id,
                         success: function(m){
		          $(tv).html(m);
		          $('#onl_ch_list').attr('scrollLeft',scrl_tmp);
			  $('#onl-tv-left').css('display',l_tmp);
			  $('#onl-tv-right').css('display',r_tmp);
                         }
                        });
		});
	}
	
	//radio
	var radio = $('.radio2');
	if (radio.length) {
		$(radio).find('li').live('click', function() {
			id = $(this).attr('rel');
			var scrl_tmp=$('#onl_radio_ch_list').attr('scrollLeft');
			var l_tmp=$('#onl-radio-left').css('display');
			var r_tmp=$('#onl-radio-right').css('display');
			//$(tv).load('/home/switchTv/channel/' + id);
			$.ajax({
                         url: '/home/switchRadio/channel/' + id,
                         success: function(m){
		          $(radio).html(m);
		          $('#onl_radio_ch_list').attr('scrollLeft',scrl_tmp);
			  $('#onl-radio-left').css('display',l_tmp);
			  $('#onl-radio-right').css('display',r_tmp);
                         }
                        });
		});
	}
	
	

	$('.wather .view span').live('click', function() {
		//$(this).parent().parent().find('.what').slideDown(150);
	});

	$('.wather .what li').live('click', function() {
		$.get('/home/switchWeather/language/'+lng+'/region/' + $(this).attr('rel'), {}, function(html) {
			//alert('/home/switchWeather/language/'+lng+'/region/');
			$('.wather').replaceWith(html);
		});
		//$('.wather').load('/site/switchWeather/region/' + $(this).attr('rel') + ' .wather.innerHTML');
	});

	var tabs = $('.onl-m');
	if (tabs.length) {
		var current;
		$(tabs).find('li').live('click', function() {
			$('.onl-' + current).hide();
			current = $(this).attr('rel');

			$(tabs).find('li').removeClass('onh');
			$(this).addClass('onh');
			$('.onl-' + current).show();
		});
	}

	/*$('a[rel*="lightbox"]').colorbox();

	var tv = $('.tv');
	if (tv.length) {
		$(tv).find('li').live('click', function() {
			$('.tv').load($(this).attr('rel'));
		});
	}

	var register = $('.reg-type');
	if (register) {
		var default_role = 'user';
		$('.reg-type li').click(function() {
			switch_role($(this).attr('rel'));
		});

		var current_role = 'user';
		switch_role = function(role) {
			$('.reg-type li').removeClass('rth');
			$('.reg-type li[rel="' + role + '"]').addClass('rth');
			$('#signup-form tr[rel*="' + current_role + '"]').hide();
			current_role = role;
			$('#signup-form tr[rel*="' + current_role + '"]').show();
			$('#signup-role').val(current_role);
		};
		switch_role(default_role);
	}*/

	// Fix for browsers which not supported placeholder
	$('body').find(':input[placeholder!=""]').each(function() {
		$(this).live('focus', function() {
			$(this).val('');
			$(this).css('color', '');
		}).live('blur', function() {
			$(this).val($(this).attr('placeholder'));
			$(this).css('color', 'darkGray');
		});
		$(this).blur();
	});
});

function GetPlayer(host, id, url, title) {
	return '<embed type="application/x-shockwave-flash" src="http://' + host + '/Static/Flash/player.swf" width="480" height="410" style="undefined" id="mpl" name="mpl" quality="high" allowscriptaccess="always" allowfullscreen="true" devconfig="http://kaztube.kz/DescribeVideo.ashx" flashvars="image=http://' + host + '/Images.ashx?id=' + id + '&amp;file=' + url + '.flv&amp;rating=5&amp;streamer=' + url + '.flv&amp;plugins=http://' + host + '/Static/Flash/mpl2.swf&amp;logo=http://' + host + '/Static/Images/kaztube_logo.png&amp;title=' + title + '&amp;description=&amp;thumbs=http://kaztube.kz/Video/' + id + '/alike&amp;addFavorite=http://kaztube.kz/Users/Login&amp;mute=false">';
    //return "<object width='480' height='390' id='player' classid='clsid:"+vid+"'><param name='movie' value='http://kaztube.kz/Static/Flash/player.swf' /><param name='allowfullscreen' value='true'/><param name='allowScriptAccess' value='always'/><param name='FlashVars' value='adRiverPreFile=http://ad.adriver.ru/cgi-bin/erle.cgi?sid=118073&adRiverPreUrl=http://ad.adriver.ru/cgi-bin/click.cgi?sid=118073&adRiverPreFile_target=blank&adRiverPreFile_bt=53&adRiverPreFile_pz=0&videoid="+vid+"&thumbs=http://kaztube.kz/Video/"+vid+"/alike&addFavorite=http://kaztube.kz/Users/Register&file="+furl+".flv&image=http://kaztube.kz/Images.ashx?id="+vid+"&rating=0&title="+vtitle+"' /><param name='wmode' value='window' /><embed name='player' FlashVars='adRiverPreFile=http://ad.adriver.ru/cgi-bin/erle.cgi?sid=118073&adRiverPreUrl=http://ad.adriver.ru/cgi-bin/click.cgi?sid=118073&adRiverPreFile_target=blank&adRiverPreFile_bt=53&adRiverPreFile_pz=0&videoid="+vid+"&thumbs=http://kaztube.kz/Video/"+vid+"/alike&addFavorite=http://kaztube.kz/Users/Register&file="+furl+".flv&image=http://kaztube.kz/Images.ashx?id="+vid+"&rating=0&title="+vtitle+"' src='http://kaztube.kz/Static/Flash/player.swf' type='application/x-shockwave-flash' width='480' height='390' allowfullscreen='true' allowScriptAccess='always' wmode='window'></embed></object>";
}

function GetYoutubePlayer(url)
{
	return '<iframe width="480" height="390" src="' + url + '" frameborder="0" allowfullscreen="yes"></iframe>';
}


function GetPlayer_new(url,title) {
 return '<object id="videoplayer636" type="application/x-shockwave-flash" data="http://www.bnews.kz/11/uppod.swf" width="500" height="375">'+
  '<param name="allowFullScreen" value="true" />'+
  '<param name="allowScriptAccess" value="always" />'+
  '<param name="wmode" value="transparent" />'+
  '<param name="movie" value="http://www.bnews.kz/11/uppod.swf" />'+
  '<param name="flashvars" value="comment='+title+'&amp;st=http://www.bnews.kz/11/styles/video82-707.txt&amp;file='+url+'.flv&amp;poster=http://www.bnews.kz/11/image.jpg&amp;link=http://uppod.ru/vfveasrs" />'+
 '</object>';
}
function GetYoutubePlayer_new(url,title)
{
 var tmp=url.split("/");
 var u=tmp[tmp.length-1];
 if(!u){ u=tmp[tmp.length-2]; }
 return '<object id="videoplayer636" type="application/x-shockwave-flash" data="http://www.bnews.kz/11/uppod.swf" width="500" height="375">'+
  '<param name="allowFullScreen" value="true" />'+
  '<param name="allowScriptAccess" value="always" />'+
  '<param name="wmode" value="transparent" />'+
  '<param name="movie" value="http://www.bnews.kz/11/uppod.swf" />'+
  '<param name="flashvars" value="comment='+title+'&amp;st=http://www.bnews.kz/11/styles/video82-707.txt&amp;file=http://www.youtube.com/v/'+u+'?version=3&amp;poster=http://www.bnews.kz/11/image.jpg&amp;link=http://uppod.ru/vfveasrs" />'+
 '</object>';
}

document.onclick=function(e){
 e = e || window.event;
 var src = e.srcElement || e.target;
 if(src.id!='weather_selected_region' && src.parentNode.id!='weather_selected_region'){
  if(document.getElementById('weather_region_list_popup')){
   if(document.getElementById('weather_region_list_popup').style.display=='block'){
    document.getElementById('weather_region_list_popup').style.display='none';
   }
  }
 } else{
  if(document.getElementById('weather_region_list_popup')){
   if(document.getElementById('weather_region_list_popup').style.display=='block'){
    document.getElementById('weather_region_list_popup').style.display='none';
   } else{
    document.getElementById('weather_region_list_popup').style.display='block';
   }
  }
 }
 if(document.getElementById("search_cat_list_in")){
  if(document.getElementById("search_cat_list_in").style.display=='block'){
   if(src.id!="search_cat_list_in" && src.id!="search_cat_list_in_in" && src.id!="search_cat_in" && src.parentNode.id!="search_cat_list_in_in"){
    document.getElementById("search_cat_list_in").style.display='none';
   }
  }	
 }
 
  if(document.getElementById("search_cat_list")){
  if(document.getElementById("search_cat_list").style.display=='block'){
   if(src.id!="search_cat_list" && src.id!="search_cat_list__in" && src.id!="search_cat" && src.parentNode.id!="search_cat_list__in"){
    document.getElementById("search_cat_list").style.display='none';
   }
  }	
 }
 
 
}


