﻿var _s = {
	go : function(){
		var text = $('#text').val()
		if(text=='')return;
		//window.open('http://search.oboz.ua/search.aspx?k='+text, '_blank');
		//window.open('http://obozrevatel.com/search_result.htm?q=' + encodeURI(text));
		
		var url = "/search_result.htm?cx=000234703784691205514:fw-ak-gykzm&ie=utf-8&cof=FORID:11&q=" + encodeURI(text);
		window.open(url);
	}
}

var _mi =
{
	over:function(e,i){
		if(eval($('.main-item .main-item-body li:first').attr('pos'))==i)
			return;

		$('.main-item .main-item-choose a').attr('class','');
		$(e).attr('class','cur');
		$('.main-item .main-item-body li:first').before($('.main-item .main-item-body li[pos="'+i+'"]')); 
	}
}

var _mi2 =
{
	over:function(e,i){
		if(eval($('.main-item .main-item-body li:first').attr('pos'))==i)
			return;

		$('.main-item .main-item-body li:first').before($('.main-item .main-item-body li[pos="'+i+'"]')); 
	}
}

var _scroll = 
{
	left : function(c,pc){
		var prefix = (pc!=null?('.'+pc+' '):'');
		$(prefix+'.'+c+' .'+c+'-item:first').before($(prefix+'.'+c+' .'+c+'-item:last'));
		var pos = $(prefix+'.'+c+' .'+c+'-item:first').attr('pos')
		$(prefix+'.'+c+'-scroller .cur-item').attr('class','item');
		$(prefix+'.'+c+'-scroller .item:eq('+pos+')').attr('class','cur-item');
	},
	right : function(c,pc){
		var prefix = (pc!=null?('.'+pc+' '):'');
		$(prefix+'.'+c+' .'+c+'-item:last').after($(prefix+'.'+c+' .'+c+'-item:first'));
		var pos = $(prefix+'.'+c+' .'+c+'-item:first').attr('pos')
		$(prefix+'.'+c+'-scroller .cur-item').attr('class','item');
		$(prefix+'.'+c+'-scroller .item:eq('+pos+')').attr('class','cur-item');
	}
}

var _banners = {
			LoadAdriver: function(){
				var banners = this;
				new adriver.Plugin.require("old.adriver").onLoadComplete(function(){
					adriver.onDomReady(function(){
						for (var key in banners) {
							if( key != 'LoadAdriver' && ('ID' in banners[key]) && ('AdriverObjParam' in banners[key]) ){
								new adriver(banners[key]['ID'], banners[key]['AdriverObjParam']);
							}
						}
					})
				});
			}
		};
		
var _accordion = {
	init:function(){
		$(".accordion .accordion-head").click(
			function(){
				if($(this).hasClass('up'))
					return;
					
				var posOld = $('.accordion .up').removeClass('up').addClass('dn').attr('pos');
				var posNew = $(this).removeClass('dn').addClass('up').attr('pos');
				$('.accordion'+posOld).slideUp();
				$('.accordion'+posNew).slideDown();
			}
		);
	}
}



$(document).ready(function() {

	//move he last list item before the first item. The purpose of this is if the user clicks to slide left he will be able to see the last item.
	$('.video-scroll-window li:first').before($('.video-scroll-window li:last')); 
	$('.video-scroll-window ul').css({'left' : -$('.video-scroll-window li').outerWidth() });
    $('.video-scroll-surface li').hover(function(){
		var pos = $(this).attr('pos');
		var first = $('.video-body-scroll li:first');
		if(first.attr('pos')!=pos){
			first.before($('.video-body-scroll li[pos="'+pos+'"]'));
		}
    });
    
	//when user clicks the image for sliding right        
	$('.video-scroll-window .right').click(function(){
    
		//get the width of the items ( i like making the jquery part dynamic, so if you change the width in the css you won't have o change it here too ) '
		var item_width = $('.video-scroll-window li').outerWidth();
        
		//calculae the new left indent of the unordered list
		var left_indent = parseInt($('.video-scroll-window ul').css('left')) - item_width;
        
		//make the sliding effect using jquery's anumate function '
		$('.video-scroll-window ul:not(:animated)').animate({'left' : left_indent},500,function(){
			//get the first list item and put it after the last list item (that's how the infinite effects is made) '
			$('.video-scroll-window li:last').after($('.video-scroll-window li:first')); 
			$('.video-scroll-window ul').css({'left' : -$('.video-scroll-window li').outerWidth() });
		}); 
	});
    
	//when user clicks the image for sliding left
	$('.video-scroll-window .left').click(function(){
        
		var item_width = $('.video-scroll-window li').outerWidth();
        
		// same as for sliding right except that it's current left indent + the item width (for the sliding right it's - item_width)
		var left_indent = parseInt($('.video-scroll-window ul').css('left')) + item_width;
        
		$('.video-scroll-window ul:not(:animated)').animate({'left' : left_indent},500,function(){    
			// when sliding to left we are moving the last item before the first list item
			$('.video-scroll-window li:first').before($('.video-scroll-window li:last')); 
			
			$('.video-scroll-window ul').css({'left' : -$('.video-scroll-window li').outerWidth() });
		});
        
	});
});

var _op = {
	click:function(){
		if($(".our-projects .dn").length == 1){
			$(".our-projects .our-projects-body").hide();
			$(".our-projects .dn").removeClass('dn').addClass('up');
		}else{
			$(".our-projects .our-projects-body").show();
			$(".our-projects .up").removeClass('up').addClass('dn');
		}
	}
}

var _photoMain =
{
	over:function(e,i){
		$(".show-inner-main .item-current").attr('class','');
		$(e).attr('class','item-current');
		$('.show-inner-main .main-item-inner').hide();
		$('.show-inner-main .main-item-inner:eq('+i+')').show()
	}
}
