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