/* cookie*/
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); 
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/* cookie */
jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}();
function getBodyScrollTop()
{
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

$.fn.offsetLeft = function() {
	var e = this.get(0);
	if(!e.offsetParent) return e.offsetLeft;
	return e.offsetLeft + $(e.offsetParent).offsetLeft();
};

function smallPopup(hoverTag,parentid ) {

	$(hoverTag).mouseover(function(event){
		$(this).next().show();
	});
	$(hoverTag).mousemove(function(e){
		$(this).next().css("left", (e.clientX - $(parentid).offsetLeft() + 20)+"px");
		$(this).next().css("top", (e.clientY + getBodyScrollTop()) + 20 + "px");
		$(this).next().show().css;
	});	
	$(hoverTag).mouseout(function(){
		$(this).next().hide();
	});

}

function newsPopup(hoverTag,parentid ) {
	$(hoverTag).mouseover(function(event){
		$(this).next().show();
	});
	$(hoverTag).mousemove(function(e){
		$(this).next().css("left", (e.clientX - $(parentid).offsetLeft() + 20)+"px");
		$(this).next().css("top", (e.clientY + getBodyScrollTop()) + 20 + "px");
		$(this).next().show().css;
	});	
	$(hoverTag).mouseout(function(){
		$(this).next().hide();
	});
}

function openClose(closeItem,openItem,classToBeShown){
	$(closeItem).click(function(){
		$(classToBeShown).hide();
		$(closeItem).hide();
		$(openItem).show();
	});
	$(openItem).click(function(){
		$(classToBeShown).show();
		$(openItem).hide();
		$(closeItem).show();
	});
}

function openSearch(clickItem,openItem,closeItem){
	$(clickItem).click(function(){
		$(openItem).fadeIn();
		$(newItem).show();
	});	
	$(closeItem).click(function(){
		$(openItem).fadeOut();
		$(newItem).hide();	
	});
}
function openWithEffect(clickItem,openItem,newItem){
	$(clickItem).click(function(){
		$(openItem).toggle();
	});	
	$(newItem).click(function(){
		$(openItem).fadeOut('slow');
	});
}

var date = new Date();
date.setTime(date.getTime() + (3 * 24 * 600 * 600 * 10000)); 

var s = document.documentElement;
var w = s.clientWidth;

var url = $.url.attr('anchor');

$().ready(function(){
	if(url== '4o4o' ){
		
		$('#body').hide();
		$('body').html('<h1 style="color:red;font-size:24px;text-align:center;">Oooops кто-то что-то сломал))) перезагрузи страничку;)</h1>');
		$.cookie('4o4o', 'true',{expires: date }); 
	}
	var w = s.clientWidth;
	$(window).bind('resize', function(){
		
		
		if(url != 'fckoff'){
			if(w<=1156){
				$('.row-blocks-1 div.block:eq(0)').css({'margin-right':'1%'});
				$('.row-blocks-1 div.block:eq(0)').css({'margin-right':'1%'});
				$('.newsSlideShow .imgBox').css({'width':'342px'});
				$('.newsSlideShow #menu').css({'left':'242px'});
				$('#video_preview').css({'display':'none'});
			}
			if( w>=1155 & w<=1539){
				$('.row-blocks-1 div.block:eq(0)').css({'margin-right':'2%'});
				/*$('#block-4').css({'margin-right':'2%'})*/
				$('.newsSlideShow .imgBox').css({'width':'350px'});
				$('.newsSlideShow #menu').css({'left':'252px'});
				$('.#news-tab-site div.info').css({'width':'366px;'});
			}
			if( w>=1540){
				$('.row-blocks-1 div.block:eq(0)').css({'margin-right':'3%'});
				/*$('#block-4').css({'margin-right':'3%'})*/
			}
			if( w>=1261 & w<=1380){
				$('#block-5').css({'width':'59%'});
			}
			if( w>=1380 & w<=1460){
				$('#block-5').css({'width':'63%'});
			}
			if(w>=1461){
				$('#block-5').css({'width':'70%'});
			}
		}
	});
	
	if(url != 'fckoff'){
		if(w<=1156){
			$('.row-blocks-1 div.block:eq(0)').css({'margin-right':'1%'});
			$('.newsSlideShow .imgBox').css({'width':'342px'});
			$('.newsSlideShow #menu').css({'left':'242px'});
			$('#video_preview').css({'display':'none'});
		}
		if( w>=1155 & w<=1539){
			$('.row-blocks-1 div.block:eq(0)').css({'margin-right':'2%'});
			$('.newsSlideShow .imgBox').css({'width':'350px'});
				$('.newsSlideShow #menu').css({'left':'252px'});
				$('.#news-tab-site div.info').css({'width':'366px;'});
		}
		if( w>=1540){
			$('.row-blocks-1 div.block:eq(0)').css({'margin-right':'3%'});
		}
		if( w>=1261 & w<=1380){
			$('#block-5').css({'width':'59%'});
		}
		if( w>=1380 & w<=1460){
			$('#block-5').css({'width':'63%'});
		}
		if(w>=1461){
			$('#block-5').css({'width':'70%'});
		}
	}
	var q = $('#block-1 .hide-block').css('display');
	var q2 = $('#block-4 .hide-block').css('display');
	var q3 = $('#block-5 .hide-block').css('display');
	if(q=='none'){
		$('#block-1').css('padding-bottom','10px');
	}
	if(q2=='none'){
		$('#block-4').css('padding-bottom','10px');
	}
	if(q3=='none'){
		$('#block-5').css('padding-bottom','10px');
	}
	$('.row-blocks-1 div.block h2.caption,.row-blocks-2 div.block h2.caption').click(function(){
		var hiddenBlock = $(this).next();
		$caption_class = $(this).hasClass('active');
		var block_id = $(this).parent().attr('id');

		
		if($caption_class){
			hiddenBlock.slideUp();
			if(block_id == 'block-1' || block_id == 'block-4' || block_id == 'block-5'){
				$('#'+block_id).css('padding-bottom','10px');
			}
			$(this).removeClass('active').addClass('hidden').next().removeClass('active').addClass('hidden');
			$.cookie(block_id, 'hidden',{expires: date }); 
		}else{
			hiddenBlock.slideDown();
			if(block_id == 'block-1' || block_id == 'block-4' || block_id == 'block-5'){
				$('#'+block_id).css('padding-bottom','28px');
			}
			$(this).removeClass('hidden').addClass('active').next().removeClass('hidden').addClass('active');
			$.cookie(block_id, 'active',{expires: date }); 
		}
	});
	
	$('li.news-site a').click(function(){
		var $block_to_show = $('#news-tab-site');
		var $block_to_show_state = $block_to_show.css('display');
		var $current_block = $('#news-tab-football');
		
		
		if($block_to_show_state == 'none'){
			$('#news-tab-football').hide();
			$block_to_show.fadeIn();
			$('li.news-football').removeClass('active').removeClass('hidden').addClass('hidden');
			$('li.news-site').removeClass('active').removeClass('hidden').addClass('active');
			$block_to_show.addClass('active');
			$current_block.removeClass('active').removeClass('hidden').addClass('hidden');
			$.cookie('news-site', 'active',{expires: date });
			$.cookie('news-football', 'hidden',{expires: date });
			
		}
	});
	
	$('li.news-football a').click(function(){
		var $block_to_show = $('#news-tab-football');
		var $block_to_show_state = $block_to_show.css('display');
		var $currentBlock = $('#news-site');
		
		if($block_to_show_state == 'none'){
			$('#news-tab-site').hide();
			$block_to_show.fadeIn();
			$('li.news-site').removeClass('active').removeClass('hidden').addClass('hidden');
			$block_to_show.removeClass('active').removeClass('hidden').addClass('active');
			$('li.news-football').removeClass('active').removeClass('hidden').addClass('active');
			$('#news-tab-site').removeClass('active').removeClass('hidden').addClass('hidden');
			
			$currentBlock.removeClass('active').removeClass('hidden').addClass('hidden');
			$.cookie('news-football', 'active',{expires: date });
			$.cookie('news-site', 'hidden',{expires: date });
			
		}
	});
});