<!--jQuery.noConflict();-->

var featuredcontentglider2={
	csszindex: 100,
	ajaxloadingmsg: '<b>Загрузка...</b>',
	glide:function(config3, showpage3, isprev3){
		var selected=parseInt(showpage3)
		if (selected>=config3.$contentdivs3.length){ //if no content exists at this index position
			alert("No content exists at page "+(selected+1)+"! Loading 1st page instead.")
			selected=0
		}
		var $target3=config3.$contentdivs3.eq(selected)
		//Test for toggler not being initialized yet, or user clicks on the currently selected page):
		if (config3.$togglerdiv.attr('lastselected')==null || parseInt(config3.$togglerdiv.attr('lastselected'))!=selected){
			var $selectedlink3=config3.$toc.eq(selected)
			config3.$next.attr('loadpage', (selected<config3.$contentdivs3.length-1)? selected+1+'pg' : 0+'pg')
			config3.$prev.attr('loadpage', (selected==0)? config3.$contentdivs3.length-1+'pg' : selected-1+'pg')
			var startpoint=(isprev3=="previous")? -config3.startpoint : config3.startpoint
			$target3.css(config3.leftortop, startpoint).css("zIndex", this.csszindex++) //hide content so it's just out of view before animating it
			var endpoint=(config3.leftortop=="left")? {left:0} : {top:0} //animate it into view
			$target3.animate(endpoint, config3.speed)
			config3.$toc.removeClass('selected')
			$selectedlink3.addClass('selected')
			config3.$togglerdiv.attr('lastselected', selected+'pg')
		}
	},

	getremotecontent:function($, config3){
		config3.$glider.html(this.ajaxloadingmsg)
		$.ajax({
			url: config3.remotecontent,
			error:function(ajaxrequest){
				config3.$glider.html('Error fetching content.<br />Server Response: '+ajaxrequest.responseText)
			},
			success:function(content){
				config3.$glider.html(content)
				featuredcontentglider2.setuptoggler3($, config3)
			}
		})
	},

	aligncontents3:function($, config3){
		config3.$contentdivs3=$("#"+config3.gliderid+" ."+config3.contentclass)
		config3.$contentdivs3.css(config3.leftortop, config3.startpoint).css({height: config3.$glider.height(), visibility: 'visible'}) //position content divs so they're out of view:
	},

	setuptoggler3:function($, config3){
		this.aligncontents3($, config3)
		config3.$togglerdiv.hide()
		config3.$toc.each(function(index){
				$(this).attr('pagenumber3', index+'pg')
				if (index > (config3.$contentdivs3.length-1))
					$(this).css({display: 'none'}) //hide redundant "toc" links
		})
		var $nextandprev=$("#"+config3.togglerid+" .next, #"+config3.togglerid+" .prev")
		$nextandprev.click(function(event){ //Assign click behavior to 'next' and 'prev' links
			featuredcontentglider2.glide(config3, this.getAttribute('loadpage'), this.getAttribute('buttontype'))
			event.preventDefault() //cancel default link action
		})
		config3.$toc.click(function(event){ //Assign click behavior to 'toc' links
			featuredcontentglider2.glide(config3, this.getAttribute('pagenumber3'))
			event.preventDefault()
		})
		config3.$togglerdiv.fadeIn(1000, function(){
			featuredcontentglider2.glide(config3, config3.selected)
			if (config3.autorotate3==true){ //auto rotate contents?
				config3.stepcount=0 //set steps taken
				config3.totalsteps=config3.$contentdivs3.length*config3.autorotate3config3[1] //Total steps limit: num of contents x num of user specified cycles)
				featuredcontentglider2.autorotate3(config3)
			}
		})
		config3.$togglerdiv.click(function(){
			featuredcontentglider2.cancelautorotate3(config3.togglerid)
		})
	},

	autorotate3:function(config3){
		var rotatespeed=config3.speed+config3.autorotate3config3[0]
		window[config3.togglerid+"timer"]=setInterval(function(){
			if (config3.totalsteps>0 && config3.stepcount>=config3.totalsteps){
				clearInterval(window[config3.togglerid+"timer"])
			}
			else{
				config3.$next.triggerHandler('click')
				config3.stepcount++
			}
		}, rotatespeed)
	},

	cancelautorotate3:function(togglerid){
		if (window[togglerid+"timer"])
			clearInterval(window[togglerid+"timer"])
	},

	getCookie3:function(Name3){
		var re=new RegExp(Name3+"=[^;]+", "i") //construct RE to search for target3 Name3/value pair
		if (document.cookie.match(re)) //if cookie found
			return document.cookie.match(re)[0].split("=")[1] //return its value
		return null
	},

	setCookie3:function(Name3, value){
		document.cookie = Name3+"="+value
	},

	init:function(config3){
		jQuery(document).ready(function($){
			config3.$glider=$("#"+config3.gliderid)
			config3.$togglerdiv=$("#"+config3.togglerid)
			config3.$toc=config3.$togglerdiv.find('.toc')
			config3.$next=config3.$togglerdiv.find('.next')
			config3.$prev=config3.$togglerdiv.find('.prev')
			config3.$prev.attr('buttontype', 'previous')
			var selected=(config3.persiststate)? featuredcontentglider2.getCookie3(config3.gliderid) : config3.selected
			config3.selected=(isNaN(parseInt(selected))) ? config3.selected : selected //test for cookie value containing null (1st page load) or "undefined" string
			config3.leftortop=(/up/i.test(config3.direction))? "top" : "left" //set which CSS property to manipulate based on "direction"
			config3.heightorwidth=(/up/i.test(config3.direction))? config3.$glider.height() : config3.$glider.width() //Get glider height or width based on "direction"
			config3.startpoint=(/^(left|up)/i.test(config3.direction))? -config3.heightorwidth : config3.heightorwidth //set initial position of contents based on "direction"
			if (typeof config3.remotecontent!="undefined" && config3.remotecontent.length>0)
				featuredcontentglider2.getremotecontent($, config3)
			else
				featuredcontentglider2.setuptoggler3($, config3)
			$(window).bind('unload', function(){ //clean up and persist
				config3.$togglerdiv.unbind('click')
				config3.$toc.unbind('click')
				config3.$next.unbind('click')
				config3.$prev.unbind('click')
				if (config3.persiststate)
					featuredcontentglider2.setCookie3(config3.gliderid, config3.$togglerdiv.attr('lastselected'))
				config3=null

			})
		})
	}
};