/* -------------------------------------------------- *
 * ToggleVal 2.1
 * Updated: 1/16/09
 * -------------------------------------------------- *
 * Author: Aaron Kuzemchak
 * URL: http://aaronkuzemchak.com/
 * Copyright: 2008-2009 Aaron Kuzemchak
 * License: MIT License
** -------------------------------------------------- */

;(function($){$.fn.toggleVal=function(theOptions){if(!theOptions||typeof(theOptions)=="object"){theOptions=$.extend({focusClass:"tv-focused",changedClass:"tv-changed",populateFrom:"default",text:null,removeLabels:false},theOptions);}
else if(typeof(theOptions)=="string"&&theOptions.toLowerCase()=="destroy"){var destroy=true;}
return this.each(function(){if(destroy){$(this).unbind("focus.toggleval").unbind("blur.toggleval").removeData("defText");return false;}
var defText="";switch(theOptions.populateFrom){case"title":defText=$(this).attr("title");$(this).val(defText);break;case"label":defText=$("label[for='"+$(this).attr("id")+"']").text();$(this).val(defText);break;case"custom":defText=theOptions.text;$(this).val(defText);break;default:defText=$(this).val();}
$(this).addClass("toggleval").data("defText",defText);if(theOptions.removeLabels==true){$("label[for='"+$(this).attr("id")+"']").remove();}
$(this).bind("focus.toggleval",function(){if($(this).val()==$(this).data("defText")){$(this).val("");}
$(this).addClass(theOptions.focusClass).removeClass(theOptions.changedClass);}).bind("blur.toggleval",function(){if($(this).val()==""){$(this).val($(this).data("defText"));}
$(this).removeClass(theOptions.focusClass);if($(this).val()!=$(this).data("defText")){$(this).addClass(theOptions.changedClass);}
else{$(this).removeClass(theOptions.changedClass);}});});};})(jQuery);

/*
 * jQuery.ScrollTo - Easy element scrolling using jQuery
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 06/05/2009
 * @author Ariel Flesler
 * @version 1.4.2
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(c){var a=c.scrollTo=function(f,e,d){c(window).scrollTo(f,e,d)};a.defaults={axis:"xy",duration:parseFloat(c.fn.jquery)>=1.3?0:1};a.window=function(d){return c(window)._scrollable()};c.fn._scrollable=function(){return this.map(function(){var e=this,d=!e.nodeName||c.inArray(e.nodeName.toLowerCase(),["iframe","#document","html","body"])!=-1;if(!d){return e}var f=(e.contentWindow||e).document||e.ownerDocument||e;return c.browser.safari||f.compatMode=="BackCompat"?f.body:f.documentElement})};c.fn.scrollTo=function(f,e,d){if(typeof e=="object"){d=e;e=0}if(typeof d=="function"){d={onAfter:d}}if(f=="max"){f=9000000000}d=c.extend({},a.defaults,d);e=e||d.speed||d.duration;d.queue=d.queue&&d.axis.length>1;if(d.queue){e/=2}d.offset=b(d.offset);d.over=b(d.over);return this._scrollable().each(function(){var l=this,j=c(l),k=f,i,g={},m=j.is("html,body");switch(typeof k){case"number":case"string":if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(k)){k=b(k);break}k=c(k,this);case"object":if(k.is||k.style){i=(k=c(k)).offset()}}c.each(d.axis.split(""),function(q,r){var s=r=="x"?"Left":"Top",u=s.toLowerCase(),p="scroll"+s,o=l[p],n=a.max(l,r);if(i){g[p]=i[u]+(m?0:o-j.offset()[u]);if(d.margin){g[p]-=parseInt(k.css("margin"+s))||0;g[p]-=parseInt(k.css("border"+s+"Width"))||0}g[p]+=d.offset[u]||0;if(d.over[u]){g[p]+=k[r=="x"?"width":"height"]()*d.over[u]}}else{var t=k[u];g[p]=t.slice&&t.slice(-1)=="%"?parseFloat(t)/100*n:t}if(/^\d+$/.test(g[p])){g[p]=g[p]<=0?0:Math.min(g[p],n)}if(!q&&d.queue){if(o!=g[p]){h(d.onAfterFirst)}delete g[p]}});h(d.onAfter);function h(n){j.animate(g,e,d.easing,n&&function(){n.call(this,f,d)})}}).end()};a.max=function(j,i){var h=i=="x"?"Width":"Height",e="scroll"+h;if(!c(j).is("html,body")){return j[e]-c(j)[h.toLowerCase()]()}var g="client"+h,f=j.ownerDocument.documentElement,d=j.ownerDocument.body;return Math.max(f[e],d[e])-Math.min(f[g],d[g])};function b(d){return typeof d=="object"?d:{top:d,left:d}}})(jQuery);


/*
 * jQuery.SerialScroll - Animated scrolling of series
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 06/14/2009
 * @author Ariel Flesler
 * @version 1.2.2
 * http://flesler.blogspot.com/2008/02/jqueryserialscroll.html
 */
;(function(a){var b=a.serialScroll=function(c){return a(window).serialScroll(c)};b.defaults={duration:1e3,axis:"x",event:"click",start:0,step:1,lock:!0,cycle:!0,constant:!0};a.fn.serialScroll=function(c){return this.each(function(){var t=a.extend({},b.defaults,c),s=t.event,i=t.step,r=t.lazy,e=t.target?this:document,u=a(t.target||this,e),p=u[0],m=t.items,h=t.start,g=t.interval,k=t.navigation,l;if(!r){m=d()}if(t.force){f({},h)}a(t.prev||[],e).bind(s,-i,q);a(t.next||[],e).bind(s,i,q);if(!p.ssbound){u.bind("prev.serialScroll",-i,q).bind("next.serialScroll",i,q).bind("goto.serialScroll",f)}if(g){u.bind("start.serialScroll",function(v){if(!g){o();g=!0;n()}}).bind("stop.serialScroll",function(){o();g=!1})}u.bind("notify.serialScroll",function(x,w){var v=j(w);if(v>-1){h=v}});p.ssbound=!0;if(t.jump){(r?u:d()).bind(s,function(v){f(v,j(v.target))})}if(k){k=a(k,e).bind(s,function(v){v.data=Math.round(d().length/k.length)*k.index(this);f(v,this)})}function q(v){v.data+=h;f(v,this)}function f(B,z){if(!isNaN(z)){B.data=z;z=p}var C=B.data,v,D=B.type,A=t.exclude?d().slice(0,-t.exclude):d(),y=A.length,w=A[C],x=t.duration;if(D){B.preventDefault()}if(g){o();l=setTimeout(n,t.interval)}if(!w){v=C<0?0:y-1;if(h!=v){C=v}else{if(!t.cycle){return}else{C=y-v-1}}w=A[C]}if(!w||t.lock&&u.is(":animated")||D&&t.onBefore&&t.onBefore(B,w,u,d(),C)===!1){return}if(t.stop){u.queue("fx",[]).stop()}if(t.constant){x=Math.abs(x/i*(h-C))}u.scrollTo(w,x,t).trigger("notify.serialScroll",[C])}function n(){u.trigger("next.serialScroll")}function o(){clearTimeout(l)}function d(){return a(m,p)}function j(w){if(!isNaN(w)){return w}var x=d(),v;while((v=x.index(w))==-1&&w!=p){w=w.parentNode}return v}})}})(jQuery);

/********************************************************************
 * jQuery Dependent Select plug-in									*
 *																	* 
 * @version		2.5													*
 * @copyright	(c) Bau Alexandru 2009 								*
 * @author 		Bau Alexandru										*
 * @email		bau.alexandru@gmail.com								*
 *																	*
 * @depends		jQuery									            *
 * 																	*
 * 																	*
 * Do not delete or modify this header!								*
 *																	* 
 * 																	*
 * Plugin call example:												*
 * 																	*
 * jQuery(function($){												*
 *																	* 
 *		SINGLE CHILD												*
 *		$('#child_id').dependent({							        *
 *			parent:	'parent_id',									*
 *			group:	'common_class'									*
 *		});															*
 *																	* 
 *		MULTIPLE CHILDS												*
 *		$('#child_id').dependent({							        *
 *			parent:	'parent_id' 									*
 *		});															*
 *																	*
 *	});																*
 *																	*
 ********************************************************************/

(function($){	// create closure

	/**
	 * Plug-in initialization
	 * @param	object	plug-in options
	 * @return 	object	this
	 */
	$.fn.dependent = function(settings){
		// merge default settings with dynamic settings
		$param = $.extend({}, $.fn.dependent.defaults, settings);

		this.each(function(){														// for each element
			$this = $(this);														// current element object

			var $parent 	= '#'+$param.parent;

			var $child	 	= $this;
			var $child_id 	= $($child).attr('id');
			var $child_cls 	= '.'+$child_id;

			if( $param.group != '' ){
				var $group	 	= '.'+$param.group;
			}

			var $index 		= 0;
			var $holder  	= 'dpslctholder';
			var $holder_cls	= '.'+$holder;

			_createHolder($holder, $holder_cls, $child, $child_id, $child_cls);

			// check if parent allready has an option selected
			if( $($parent).val() != 0 ) {
				$title = $($parent).find('option:selected').attr('title');
				$($child).find('option[class!='+$title+']').remove();
				$($child).prepend('<option value="">Все виды</option>');
			} else {
				// remove the child's options and add a default option
				$($child).find('option').remove();
				$($child).append('<option value="">Все виды</option>');
			}

			_parentChange($parent, $child, $group, $holder_cls, $child_cls);

		});

		return this;
	};

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	/*********************************
	 * BEGIN PLUG-IN PRIVATE METHODS *
	 *********************************/

	/**
	 * Private function description
	 */

	function _createHolder($holder, $holder_cls, $child, $child_id, $child_cls){

		// create a select to hold the options from all this child
		var $is_created = $($holder_cls+' '+$child_id).size();

		if( $is_created == 0 ){
			$('body').append('\n\n<select class="'+$holder+' '+$child_id+'" style="display:none">\n</select>\n');
		}

		// add options to the holder
		$($child).find('option[value!=]').each(function(){

			$value = $(this).attr('value');
			$class = $(this).attr('class');
			$title = $(this).attr('title');
			$text  = $(this).text();

			$($holder_cls+$child_cls).append('<option value="'+$value+'" class="'+$class+'" title="'+$title+'">'+$text+'</option>\n');
		});

	}

	function _parentChange($parent, $child, $group, $holder_cls, $child_cls){

		// on change event
		$($parent).bind('change', function(){

			// remove all the child's options
			$($child).find('option[value!=]').remove();

			$index = $($group).index($(this))
			// set all the selects from the group to the default option
			if( $param.group != '' ){
				$($group+':gt('+ $index +')').find('option[value!=]').remove();
			}

			$title = $(this).find('option:selected').attr('title');
			// add options to the child mask from the holder
			$($holder_cls+$child_cls).find('option[class='+$title+']').each(function(){

				$value = $(this).attr('value');
				$class = $(this).attr('class');
				$title = $(this).attr('title');
				$text  = $(this).attr('text');

				$($child).append('<option value="'+$value+'" class="'+$class+'" title="'+$title+'">'+$text+'</option>');
			});

		});

	}

	/********************************
	 * /END PLUG-IN PRIVATE METHODS *
	 ********************************/

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	/************************************
	 * BEGIN PLUG-IN DEFAULT PARAMETERS *
	 ************************************/

	$.fn.dependent.defaults = {	
		parent:		'parent_id'
	};

	/***********************************
	 * /END PLUG-IN DEFAULT PARAMETERS *
	 ***********************************/

})(jQuery);		// end closure

$(document).ready(function() {
	$(".search-block input, .forms-block .i-p").toggleVal();
	$('.hor-scrollable').serialScroll({
			target: '.hor-scrollable-i',
			items:'li',
			prev:'.l-ar',
			next:'.r-ar',
			duration:700,
			axis:'x',
			force:true,
			stop:true,
			lock:false,
			cycle:true,
			start: 0,
			step:4,
			exclude:3
		});
});