$(function(){

	var self = this,
		$seasonBlock = $('#season_block'),
		$winterBtn = $seasonBlock.find('.season_nav li.w'),
		$summerBtn = $seasonBlock.find('.season_nav li.s'),
		$winterBtnH = $winterBtn.find('span'),
		$summerBtnH = $summerBtn.find('span'),
		$arrow = $seasonBlock.find('.arrow'),
		$flashCarousel = $('#flashCarousel'),
		month = new Date();

	$winterBtn.click(function(){
		$winterBtnH.animate({ width:38 }, 300);
		$summerBtnH.animate({ width:0 }, 300);
		$arrow.animate({ right:159 }, 300);
		$seasonBlock.removeClass('summer').addClass('winter');
		self.showWinter();
	});

	$summerBtn.click(function(){
		$winterBtnH.animate({ width:0 }, 300);
		$summerBtnH.animate({ width:38 }, 300);
		$arrow.animate({ right:112 }, 300);
		$seasonBlock.removeClass('winter').addClass('summer');
		self.showSummer();
	});

	this.showSummer = function(){

		var n = parseInt(new Date().getTime().toString().substring(0, 10));

		var code =
			"<object id='carouselFlash' type='application/x-shockwave-flash' data='/gk/swf/carousel.swf?"+n+"' width='741' height='270'>"+
				"<param name='wmode' value='transparent' />"+
				"<param name='movie' value='/gk/swf/carousel.swf?"+n+"' />"+
				"<param name='quality' value='high' />"+
				"<param name='menu' value='false' />"+
				"<param name='allowScriptAccess' value='always' />"+
				"<param id='carouselXML' name='flashVars' value='xmlUri=/gk/xml/summer.php' />"+
			"</object>";

		$flashCarousel.html(code);
	}

	this.showWinter = function(){

		var n = parseInt(new Date().getTime().toString().substring(0, 10));

		var code =
			"<object id='carouselFlash' type='application/x-shockwave-flash' data='/gk/swf/carousel.swf?"+n+"' width='741' height='270'>"+
				"<param name='wmode' value='transparent' />"+
				"<param name='movie' value='/gk/swf/carousel.swf?"+n+"' />"+
				"<param name='quality' value='high' />"+
				"<param name='menu' value='false' />"+
				"<param name='allowScriptAccess' value='always' />"+
				"<param id='carouselXML' name='flashVars' value='xmlUri=/gk/xml/winter.php' />"+
			"</object>";

		$flashCarousel.html(code);
	}

	if(month.getMonth() < 10 && month.getMonth() > 2){
		$winterBtnH.css({ width:0 });
		$summerBtnH.css({ width:38 });
		$arrow.css({ right:112 });
		$seasonBlock.removeClass('winter').addClass('summer');
		self.showSummer();
	}else{
		$winterBtnH.css({ width:38 });
		$summerBtnH.css({ width:0 });
		$arrow.css({ right:159 });
		$seasonBlock.removeClass('summer').addClass('winter');
		self.showWinter();
	}

	// maptrack
	var $show = $('.show'),
		$hide = $('.hide'),
		$control = $('.control'),
		$route = $('#route'),
		$bg = $('.bg'),
		$route_red = $('.route_red'),
		$route_black = $('.route_black'),
		$route_blue = $('.route_blue'),
		$route_green = $('.route_green'),
		$symbols = $('.symbols'),
		$lifts = $('.lifts');
	// checkbox controls
	var $ch1 = $('#ch11'),
		$ch2 = $('#ch22'),
		$ch_1 = $('#сh1'),
		$ch_2 = $('#ch2'),
		$ch_route_red = $('#route_red'),
		$ch_route_blue = $('#route_blue'),
		$ch_route_green = $('#route_green'),
		$ch_route_black = $('#route_black');
	
	var showControl = function(){
		$bg.show();
				
		if ($ch_1.attr('checked')) {
			$symbols.show();
		}
		if ($ch_1.attr('checked')) {
			$lifts.show();
		}
		if ($ch_route_red.attr('checked')) {
			$route_red.show();
		}
		if ($ch_route_black.attr('checked')) {
			$route_black.show();
		}
		if ($ch_route_blue.attr('checked')) {
			$route_blue.show();
		}
		if ($ch_route_green.attr('checked')) {
			$route_green.show();
		}				
	}
	
	var hideControl = function(){
		$bg.hide();
		$route_red.hide();
		$route_black.hide();
		$route_blue.hide();
		$route_green.hide();
		$symbols.hide();
		$lifts.hide();
	}
	
	$hide.click(function(){
		$control.hide();
		$hide.hide();
		$show.show();
		hideControl();
	});
	
	$show.click(function(){
		$control.show();
		$show.hide();
		$hide.show();
		showControl();
	});
	
	$ch1.click(function(){
		$symbols.toggle();
	});
	
	$ch2.click(function(){
		$lifts.toggle();		
	});
	
	$ch_route_red.click(function(){
		$route_red.toggle();
	});
	
	$ch_route_blue.click(function(){
		$route_blue.toggle();
	});
	
	$ch_route_green.click(function(){
		$route_green.toggle();
	});
	
	$ch_route_black.click(function(){
		$route_black.toggle();
	});
	
});

