//-----------------rss onclick-------------------------
$( document ).ready(
	function()
	{
	  $( 'a.soc.rss' ).click(function()
			{
			  var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
			  dcsMultiTrack('DCSext.UA','UA.RSS.'+webtrendMetaTag);
			});
    $( 'a.soc.youtube' ).click(function()
			{
			  var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
			  dcsMultiTrack('DCSext.UA','UA.Change-Site_yt.'+webtrendMetaTag,'WT.seg_2','Change-Site_Brand-Social-Community');
			});
    $( 'a.soc.twitter' ).click(function()
			{
			  var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
			  dcsMultiTrack('DCSext.UA','UA.Change-Site_tw.'+webtrendMetaTag,'WT.seg_2','Change-Site_Brand-Social-Community');
			});
    $( 'a.soc.fb' ).click(function()
			{
			  var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
			  dcsMultiTrack('DCSext.UA','UA.Change-Site_fb.'+webtrendMetaTag,'WT.seg_2','Change-Site_Brand-Social-Community');
			});
		$('a[href*=mini.com]').click(function()
		  {
		    var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
				dcsMultiTrack('DCSext.UA','UA.Change-Site_NSC.'+webtrendMetaTag,'WT.seg_1','Change-Site_NSC');
			});
		$('a[href*=wrcshop.com]').click(function()
		  {
		    var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
				dcsMultiTrack('DCSext.UA','UA.Change-Site_WRCShop.'+webtrendMetaTag,'WT.seg_1','Change-Site_NSC');
			});

	});

//-----------------------main menu-------------------------
$( document ).ready(
	function()
	{
		var mainMenu = $( '#topmenu' );
		var mainMenuItems = $( '#topmenu li' );
		if( mainMenuItems.length > 0 )
		{
			$.each(
				mainMenuItems,
				function( index, item )
				{
					$( item ).mouseenter(
						function( event )
						{
							if( $( this ).hasClass( 'item' ) )
							{
								$( this ).children( 'ul.sub-menu' ).fadeIn( 200 );
							}
							else
							{
								$( this ).children( 'ul' ).fadeIn( 200 );
							}
						}
					);
					$( item ).mouseleave(
						function( event )
						{
							if( $( this ).hasClass( 'item' ) )
							{
								$( this ).children( 'ul.sub-menu' ).fadeOut( 200 );
							}
							else
							{
								$( this ).children( 'ul' ).fadeOut( 200 );
							}
						}
					);
				}
			);
		}
	}
);

//-----------------------left menu----------------------------
$( document ).ready(
	function()
	{
		//var advLeftMenu = new adnavcedLeftMenu();
		//advLeftMenu.initialize( '#left-menu', '#left-menu div.left-menu-item', 'div.homepage_content_item' );
		//advLeftMenu.initialize( '#left-menu' );
		if ('#left-menu')
		{
      var dock = new MacStyleDock( '#left-menu', 'div.homepage_content_item' , 70, 90, 2);
			/*$('#left-menu img').click(function()
				{
				  var index = $.inArray(this, $('#left-menu img'));
				  location.hash = '#'+index;
				});*/
		}
	}
);

//-----------------------news functionality----------------------------
$( document ).ready(
	function()
	{
	  var news = $('div.class_news');
		var newsFolder = $( 'div.class_newsfolder' );
		var newsContent = $( 'div.news_content' );
		var categories = $( 'ul.categories li a' );
		var categoriesImages = $( 'div.bmw_backgroud' );
		var currentCategorySelect = $( 'ul.categories li.current a' );
		if( currentCategorySelect.length > 0 )
		{
			var currentCategory = $( currentCategorySelect ).attr( 'rel' );
		}
		else
		{
			var currentCategory = -1;
		}
		if( newsFolder.length > 0 )
		{
			$.each( categories,
				function(index, item)
				{
					$( item ).click(
						function( event )
						{
							clicked = $( this ).attr( 'rel' );
							if( clicked != currentCategory )
							{
								var url = siteUrl + $( this ).attr( 'href' );
								$( newsContent ).html( '' );
								$( 'div.loader' ).show();
								$( newsContent ).load( url,
									function()
									{
										$( 'div.loader' ).hide();
										$( 'div.bmw_content_bg' ).css( 'background-image', 'url(' + $( categoriesImages ).find( 'img[rel=' + clicked + ']' ).attr('src') + ')' );
										var webtrendTracking = $( 'a.webtrend_multitracking_link' );
										if( webtrendTracking.length == 1 )
										{
											var webtrendUrl = $( webtrendTracking ).attr( 'href' );
											var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
											var webtrendTitle = $( 'title' ).text();
											if (window.dcsMultiTrack)
											{
												dcsMultiTrack('DCS.dcsuri', webtrendUrl, 'WT.ti', webtrendTitle, 'WT.cg_n', webtrendMetaTag );
											}
										}
										Cufon.replace('div.news_teaser h1 a, h2.news_category a, div.news_teaser a.more');
									}
								);
								$( 'ul.categories li' ).find( 'a[rel=' + currentCategory + ']' ).parent().removeClass( 'current' );
								$( this ).parent().addClass( 'current' );
								currentCategory = clicked;
							}
							return false;
						}
					);
				}
			);
			$( 'h2.news_category a' ).live( 'click',
				function( event )
				{
					clicked = $( this ).attr( 'rel' );
					if( clicked != currentCategory )
					{
						var existCategory = $( 'ul.categories li' ).find( 'a[rel=' + clicked + ']' );
						if( existCategory.length > 0 )
						{
							var url = siteUrl + $( 'ul.categories li' ).find( 'a[rel=' + clicked + ']' ).attr( 'href' );
							$( newsContent ).html( '' );
							$( 'div.loader' ).show();
							$( newsContent ).load( url,
								function()
								{
									$( 'div.loader' ).hide();
									$( 'div.bmw_content_bg' ).css( 'background-image', 'url(' + $( categoriesImages ).find( 'img[rel=' + clicked + ']' ).attr('src') + ')' );
									var webtrendTracking = $( 'a.webtrend_multitracking_link' );
									if( webtrendTracking.length == 1 )
									{
										var webtrendUrl = $( webtrendTracking ).attr( 'href' );
										var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
										var webtrendTitle = $( 'title' ).text();
										if (window.dcsMultiTrack)
                        {
                          dcsMultiTrack('DCS.dcsuri', webtrendUrl, 'WT.ti', webtrendTitle, 'WT.cg_n', webtrendMetaTag );
                        }
									}
								}
							);
							$( 'ul.categories li' ).find( 'a[rel=' + currentCategory + ']' ).parent().removeClass( 'current' );
							$( 'ul.categories li' ).find( 'a[rel=' + clicked + ']' ).parent().addClass( 'current' );
							currentCategory = clicked;
						}
					}
					return false;
				}
			);
			$( 'div.pagenavigator a' ).live( 'click',
				function( event )
				{
					var addSlash = "/";
					if( this.pathname.substring( 0, 1 ) == "/" )
					{
						addSlash = "";
					}
					if( iframe )
					{
						var url = siteUrl + addSlash + this.pathname + "/(iframe)/true?frameSrc=http://www.mini.de/mini2010_prod/_common/_html/xss.htm&frameId=main_stage";
					}
					else
					{
						var url = siteUrl + addSlash + this.pathname;
					}
					$( newsContent ).children( 'div.news_items, div.bottom_paginator' ).html( '' );
					$( 'div.loader' ).show();
					$( newsContent ).load( url,
						function()
						{
							$( 'div.loader' ).hide();
							var webtrendTracking = $( 'a.webtrend_multitracking_link' );
							if( webtrendTracking.length == 1 )
							{
								var webtrendUrl = $( webtrendTracking ).attr( 'href' );
								var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
								var webtrendTitle = $( 'title' ).text();
                if (window.dcsMultiTrack)
                        {
                          dcsMultiTrack('DCS.dcsuri', webtrendUrl, 'WT.ti', webtrendTitle, 'WT.cg_n', webtrendMetaTag );
                        }
							}
							Cufon.replace('div.news_teaser h1 a, h2.news_category a, div.news_teaser a.more');
						}
					);
					return false;
				}
			);
			$( 'div.loader' ).css( 'display', 'none' );
			$( 'div.loader' ).css( 'visibility', 'visible' );
		}
	}
);

//------------------------language-------------------------
$( document ).ready(
	function()
	{
		$( 'div.footer_item.language' ).mouseenter(
			function( event )
			{
				$( this ).children( 'div.languages_popup' ).fadeIn( 300 );
				return false;
			}
		);
		$( 'div.footer_item.language' ).mouseleave(
			function( event )
			{
				$( this ).children( 'div.languages_popup' ).fadeOut( 300 );
				return false;
			}
		);
		$( 'div.languages_popup a.close_popup' ).click(
			function( event )
			{
				$( this ).parents( 'div.languages_popup' ).fadeOut( 300 );
				return false;
			}
		);
	}
);

//------------------------news Gallery-------------------------
$( document ).ready(
	function()
	{
		var newsGalleryExist = $( 'div.gallery_navigation div.navigation_content' );
		if( newsGalleryExist.length > 0 )
		{
			var newsgallery = new newsGallery();
			var url = window.location;
			if( url.hash != '' )
			{
				var anchor = parseInt( url.hash.substring(1) );
				newsgallery.currentObject = anchor;
			}
			newsgallery.initialize( 'div.gallery_navigation div.navigation_content', 'div.gallery_navigation div.navigation_content div.item', 'div.gallery_items div.item', 'div.gallery_arrow.previous a, div.gallery_items a.previous', 'div.gallery_arrow.next a, div.gallery_items a.next' );
		}
	}
);

//------------------------news Scroller-------------------------
$( document ).ready(
	function()
	{
		
		var newsGalleryExist = $( 'div.class_news div.gallery_preview div.item' );
		if (newsGalleryExist.length == 0)
		    {
          newsGalleryExist = $( 'div.class_rally_map div.gallery_preview div.item' );
        }
		if( newsGalleryExist.length > 0 )
		{
			var newsscroller = new newsScroller();
			newsscroller.initialize(  'div.gallery_items div.item', 'div.gallery_items a.previous', 'div.gallery_items a.next' );
		}
	}
);

//------------------------drivers page-------------------------
$( document ).ready(
	function()
	{
		$("#entry-driver .item-entry .content").jScrollPane({scrollbarWidth:18, showArrows:true});
		$("#slider-lz").lzslider();
		var drivers = $( '#slider-lz div.slide-item' );
		var teaserContent = $('div.bottom_teasers');
		var driversContent = $( 'div.dtiver-info' );
		var currentDrivers = $( drivers ).index( $( '#slider-lz div.slide-item.active-slide' ) );
		
		if( drivers.length > 0 )
		{
			$.each( drivers,
				function( index, item )
				{
					$( item ).click(
						function( event )
						{
							if( currentDrivers != index )
							{
								var link = $( drivers[ index ] ).children( 'a' ).attr( 'href' );
								if( link.substr( 0, 1 ) == "/" )
								{
									var url = siteUrl + link;
								}
								else
								{
									var url = siteUrl + "/" + link;
								}
								$( drivers[ currentDrivers ] ).removeClass( 'active-slide' );
								$( drivers[currentDrivers] ).animate( { 'opacity': 0.5 }, 300 );
								$( driversContent ).html( '' );
								var teaserURL = '/' + siteAccessName + '/teasers/bottom/'+$(this).children('a').attr('rel');
								$( teaserContent ).load(teaserURL,
									function()
									{
										var teasersBlocks = $( 'div.teasers_block' );
										if( teasersBlocks.length == 3 )
										{
											window.teas = new teasers();
											window.teas.initialize( $( teasersBlocks[0] ).children( 'div.teaser_item' ), $( teasersBlocks[1] ).children( 'div.teaser_item' ), $( teasersBlocks[2] ).children( 'div.teaser_item' ), 'div.teasers_container a.previous', 'div.teasers_container a.next' );
										}
										if ((siteAccessName != 'jp')||(siteAccessName == 'jp')&&(siteUri.indexOf('iframe') == -1)&&(navigator.userAgent.match(/facebookexternalhit/i) == null ))
										{
											Cufon.replace('span.location_text');
										}
									}
								);
								$( driversContent ).load( url,
									function()
									{
										var facebook_ajax_link = $( 'a.facebook_ajax_link' );
										if( facebook_ajax_link.length > 0 )
										{
											$( '#facebook_obj' ).html( '' ).append( $( '<fb:like show_faces="false" layout="button_count" colorscheme="light" font="arial"></fb:like>' ).attr( 'href', $( 'a.facebook_ajax_link' ).attr( 'href' ) ) );
											if( typeof FB != 'undefined' )
											{
												FB.init( {
													appId  : 156503637737805,
													status : false,
													cookie : true,
													xfbml  : true
												} );
											}
										}

                    $("#entry-driver .content").jScrollPaneRemove();
                    $("#entry-driver .content").jScrollPane({scrollbarWidth:18, showArrows:true});
										$( 'div.bmw_content_bg' ).css( 'background-image', 'url(' + $( driversContent ).find( 'div.driver-foto a' ).attr( 'href' ) + ')' );
										var webtrendTracking = $( 'a.webtrend_multitracking_link' );
										if( webtrendTracking.length == 1 )
										{
											var webtrendUrl = $( webtrendTracking ).attr( 'href' );
											var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
											var webtrendTitle = $( 'title' ).text();
											if (window.dcsMultiTrack)
                        {
                          dcsMultiTrack('DCS.dcsuri', webtrendUrl, 'WT.ti', webtrendTitle, 'WT.cg_n', webtrendMetaTag );
                        }
											
										}
                    if ((siteAccessName != 'jp')||(siteAccessName == 'jp')&&(siteUri.indexOf('iframe') == -1)&&(navigator.userAgent.match(/facebookexternalhit/i) == null ))
                      {
                        Cufon.replace('.minitype2v');
                      }
                      set_drivers_gallery();
									}
								);
								
								currentDrivers = index;
								$( drivers[ currentDrivers ] ).addClass( 'active-slide' );
							}
							return false;
						}
					);
					
					$( item ).mouseenter(
						function( event )
						{
							if( currentDrivers != index )
							{
								$( this ).animate( { 'opacity': 1 }, 300 );
							}
						}
					);
					
					$( item ).mouseleave(
						function( event )
						{
							if( currentDrivers != index )
							{
								$( this ).animate( { 'opacity': 0.5 }, 300 );
							}
						}
					);
				}
			);
			$(".driver-description .link span").live( 'click',
				function()
				{
          var existDesc = $(".driver-description .entry .item-entry");
					var index = $(".driver-description .link span").index(this);
					$( this ).addClass("active-link").siblings("span").removeClass("active-link");
					$( existDesc ).hide();
					$( existDesc[index] ).addClass("active-desc").fadeIn();
					//$(".driver-description .entry .item-entry:not(.active-desc)").hide();
					if( $(".driver-description .entry .item-entry:eq("+index+")").hasClass( 'gallery' ) )
					{
						jQuery('#entry-driver .item-entry .content').jScrollPaneRemove();
					}
					else
					{
						jQuery('#entry-driver .item-entry .content').jScrollPaneRemove();
						$("#entry-driver .item-entry .content").jScrollPane({scrollbarWidth:18, showArrows:true});
					}
					Cufon.replace('.driver-description .link span');
					return false;
				}
			);
		}
		
		var facebook_ajax_link = $( 'a.facebook_ajax_link' );
		if( facebook_ajax_link.length > 0 )
		{
			$( '#facebook_obj' ).children().attr( 'href', $( 'a.facebook_ajax_link' ).attr( 'href' ) );
		}
	}
);

//------------------------teasers--------------------------------
$( document ).ready(
	function()
	{
		var teasersBlocks = $( 'div.teasers_block' );
		if( teasersBlocks.length == 3 )
		{
			window.teas = new teasers();
			window.teas.initialize( $( teasersBlocks[0] ).children( 'div.teaser_item' ), $( teasersBlocks[1] ).children( 'div.teaser_item' ), $( teasersBlocks[2] ).children( 'div.teaser_item' ), 'div.teasers_container a.previous', 'div.teasers_container a.next' );
		}
	}
);

//------------------------cars page--------------------------------
$( document ).ready(
	function()
	{
		var carContent = $( 'div.car_view' );
		var teaserContent = $('div.bottom_teasers');
		var carMenu = $( 'div.car_series a.car_link' );
		var carDetails = $( 'div.car_view a.car_detail' );
		var lightbox = $( '#car_lightbox div.car_lightbox_content' );
		var currentCar = $( carMenu ).index( $( 'div.car_series a.car_link.active' ) );
		
		var background = $( carContent ).find( 'a.background' );
		if( background.length > 0 )
		{
			if( background.length > 1 )
			{
				var rand = parseInt( background.length * Math.random() );
				$( 'div.bmw_content_bg' ).css( 'background-image', 'url(' + $( background[rand] ).attr('href') + ')' );
			}
			else
			{
				$( 'div.bmw_content_bg' ).css( 'background-image', 'url(' + $( background[0] ).attr('href') + ')' );
			}
		}
		
		if( carMenu.length > 0 )
		{
			$.each( carMenu,
				function( index, item )
				{
					$( item ).click(
						function( event )
						{
							if( currentCar != index )
							{
								if( iframe )
								{
									var url = siteUrl + '/' + this.pathname;
								}
								else
								{
									var url = siteUrl + '/' + this.pathname.substring(3,this.pathname.length);
								}
								var teaserURL = '/' + siteAccessName + '/teasers/bottom/'+$(this).attr('rel');
								//console.log( teaserURL );
								$( teaserContent ).load(teaserURL,
									function()
									{
										var teasersBlocks = $( 'div.teasers_block' );
										if( teasersBlocks.length == 3 )
										{
											window.teas = new teasers();
											window.teas.initialize( $( teasersBlocks[0] ).children( 'div.teaser_item' ), $( teasersBlocks[1] ).children( 'div.teaser_item' ), $( teasersBlocks[2] ).children( 'div.teaser_item' ), 'div.teasers_container a.previous', 'div.teasers_container a.next' );
										}
										if ((siteAccessName != 'jp')||(siteAccessName == 'jp')&&(siteUri.indexOf('iframe') == -1)&&(navigator.userAgent.match(/facebookexternalhit/i) == null ))
										{
											Cufon.replace('span.location_text');
											Cufon.replace('span.car_detail_description');
										}
									}
								);
								$( carContent ).load( url,
									function()
									{
										var facebook_ajax_link = $( 'a.facebook_ajax_link' );
										if( facebook_ajax_link.length > 0 )
										{
											$( '#facebook_obj' ).html( '' ).append( $( '<fb:like show_faces="false" layout="button_count" colorscheme="light" font="arial"></fb:like>' ).attr( 'href', $( 'a.facebook_ajax_link' ).attr( 'href' ) ) );
											if( typeof FB != 'undefined' )
											{
												FB.init( {
													appId  : 156503637737805,
													status : false,
													cookie : true,
													xfbml  : true
												} );
											}
										}
										var background = $( carContent ).find( 'a.background' );
										if( background.length > 0 )
										{
											if( background.length > 1 )
											{
												var rand = parseInt( background.length * Math.random() );
												$( 'div.bmw_content_bg' ).css( 'background-image', 'url(' + $( background[rand] ).attr('href') + ')' );
											}
											else
											{
												$( 'div.bmw_content_bg' ).css( 'background-image', 'url(' + $( background[0] ).attr('href') + ')' );
											}
										}
										var webtrendTracking = $( 'a.webtrend_multitracking_link' );
										if( webtrendTracking.length == 1 )
										{
											var webtrendUrl = $( webtrendTracking ).attr( 'href' );
											var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
											var webtrendTitle = $( 'title' ).text();
											if (window.dcsMultiTrack)
                        {
                          dcsMultiTrack('DCS.dcsuri', webtrendUrl, 'WT.ti', webtrendTitle, 'WT.cg_n', webtrendMetaTag );
                        }
											
										}
										
										//starting animation
										$.each( $( 'div.car_view a.car_detail' ),
											function( index, item )
											{
												setTimeout(
													function()
													{
														$( item ).find( 'img' ).animate( { 'width': 42, 'height': 42, 'top': 0, 'left': 0  }, 700,
															function()
															{
																$( item ).addClass( 'bg' );
																$( this ).remove();
															}
														);
													},
													1000 + ( 2 * parseInt( $( item ).css( 'left' ) ) )
												);
						
											}
										);
										
									}
								);
								$( carMenu[currentCar] ).removeClass( 'active' );
								$( carMenu[index] ).addClass( 'active' );
								currentCar = index;
							}
							return false;
						}
					);
				}
			);
		}
		
		if( carDetails.length > 0 )
		{
			//starting animation
			$.each( carDetails,
				function( index, item )
				{
					setTimeout(
						function()
						{
							$( item ).find( 'img' ).animate( { 'width': 42, 'height': 42, 'top': 0, 'left': 0  }, 700,
								function()
								{
									$( item ).addClass( 'bg' );
									$( this ).remove();
								}
							);
						},
						1500 + ( 2 * parseInt( $( item ).css( 'left' ) ) )
					);
						
				}
			);
			
			$( carDetails ).live( 'click',
				function( event )
				{
					var url = siteUrl + '/' + this.pathname;
					$( lightbox ).html( '' );
					$( lightbox ).parent().fadeIn( 700 );
					$( lightbox ).load( url,
						function()
						{
							$( lightbox ).find( 'div.description_text' ).height( $( '#car_lightbox div.car_lightbox_content' ).height() - $( lightbox ).find( 'div.description_col h1' ).height() - 10 );
							jQuery('#car_lightbox div.description_text').jScrollPaneRemove();
							$("#car_lightbox div.description_text").jScrollPane({scrollbarWidth:9, showArrows:true});
							var webtrendTracking = $( 'a.webtrend_multitracking_link_car_desc' );
							if( webtrendTracking.length == 1 )
							{
								var webtrendUrl = $( webtrendTracking ).attr( 'href' );
								var webtrendMetaTag = $( 'meta[name="WT.cg_n"]' ).attr( 'content' );
								var webtrendTitle = $( 'title' ).text();
								if (window.dcsMultiTrack)
								{
									dcsMultiTrack('DCS.dcsuri', webtrendUrl, 'WT.ti', webtrendTitle, 'WT.cg_n', webtrendMetaTag );
								}
								
							}
							if ((siteAccessName != 'jp')||(siteAccessName == 'jp')&&(siteUri.indexOf('iframe') == -1)&&(navigator.userAgent.match(/facebookexternalhit/i) == null ))
							{
								Cufon.replace('h1');
							}
						}
					);
					return false;
				}
			);
			
			$( carDetails ).live( 'mouseenter',
				function( event )
				{
					//$( this ).find( 'img' ).animate( { 'opacity': 1 }, 100 );
					$( this ).find( 'span.car_detail_description' ).show();
				}
			);
			
			$( carDetails ).live( 'mouseleave',
				function( event )
				{
					//$( this ).find( 'img' ).animate( { 'opacity': 0.5 }, 100 );
					$( this ).find( 'span.car_detail_description' ).hide();
				}
			);
			
		}
		$( 'a.close_lightbox' ).click(
			function( event )
			{
				$( this ).parent().fadeOut( 700 );
				$( this ).parent().children( 'div.car_lightbox_content' ).html( '' );
			}
		);
		
		var facebook_ajax_link = $( 'a.facebook_ajax_link' );
		if( facebook_ajax_link.length > 0 )
		{
			$( '#facebook_obj' ).children().attr( 'href', $( 'a.facebook_ajax_link' ).attr( 'href' ) );
		}
	}
);

//------------------------partner page--------------------------------
$( document ).ready(
	function()
	{
		var partnerItem = $( 'div.class_parnter div.partners div.item' );
		var leftArrow = $( 'div.class_parnter a.arrow_prev' );
		var rightArrow = $( 'div.class_parnter a.arrow_next' );
		var currentDescription = 0;
		var previousDescription = 0;
		if( partnerItem.length > 0 )
		{
			var currentDescription = $( 'div.class_parnter div.partners div.item' ).index( $( 'div.class_parnter div.partners div.item.curent' ) );
			var previousDescription = currentDescription;
			
			function rotatingDescription( direction )
			{
				previousDescription = currentDescription;
				currentDescription = currentDescription + direction;
				
				if( currentDescription < 0 )
				{
					currentDescription = partnerItem.length - 1;
				}
				if( currentDescription >= partnerItem.length )
				{
					currentDescription = 0;
				}
				
				$( partnerItem[previousDescription] ).fadeOut( 700 );
				$( partnerItem[currentDescription] ).fadeIn( 700 );
				
			}
			$( leftArrow ).click(
				function( event )
				{
					rotatingDescription( -1 );
				}
			);
			
			$( rightArrow ).click(
				function( event )
				{
					rotatingDescription( 1 );
				}
			);
		}
	}
);

//------------------------social media------------------------------
$( document ).ready(
	function( event )
	{
		var social_media_link = $( 'div.social_media' );
		var social_media_close = $( 'div.social_big_popup a.nav_button' );
		var social_media_block = $( 'div.social_media div.social_big_popup' );
		var lastTime = new Date().getTime();
		var lastTimeLeave = new Date().getTime();
		var timeoutFunction = null;
		if( social_media_link.length > 0 )
		{
			$( social_media_link ).mouseenter(
				function( event )
				{
					newTime = new Date().getTime();
					if( ( newTime - lastTimeLeave ) < 250 )
					{
						clearTimeout( timeoutFunction );
					}
					if( ( newTime - lastTime ) > 200 )
					{
						$( social_media_block ).animate( { 'height': 100 }, 100,
							function()
							{
								$( social_media_block ).css( 'overflow', 'visible' );
							}
						);
					}
				}
			);
			$( social_media_link ).mouseleave(
				function( event )
				{
					lastTimeLeave = new Date().getTime();
					timeoutFunction = setTimeout( 
						function()
						{
							lastTime = new Date().getTime();
							$( social_media_block ).css( 'overflow', 'hidden' );
							$( social_media_block ).animate( { 'height': 0 }, 100 );
						},
						300
					);
					return false;
				}
			);
			$( social_media_close ).click(
				function( event )
				{
					lastTime = new Date().getTime();
					$( social_media_block ).css( 'overflow', 'hidden' );
					$( social_media_block ).animate( { 'height': 0 }, 100 );
					return false;
				}
			);
		}
	}
);

//-----------------------mini slider----------------------------
$( window ).load(
	function()
	{
		var generalBlock = $( '#mini_slider' );
		var unclickable = $( '#mini_slider' ).hasClass( 'unclickable' );
		var contentBlock = $( '#mini_slider div.mini_slider_content' );
		var contentItems = $( '#mini_slider div.mini_slider_content div.item' );
		var controlLeft = $( '#mini_slider div.arrow-prev' );
		var controlRight = $( '#mini_slider div.arrow-next' );
		var objectsCount = 0;
		var contentWidth = 0;
		var generalWidth = $( generalBlock ).width();
		var keys = { 'left': false, 'right': false };
		var mouseDisturion = 10;
		var mouseState = { 'clicked': false, 'firstMouseX': 0, 'lastMouseX': 0, 'currentMouseX': 0, 'shouldClick': false };
		var currentLeft = 0;
		var speed = 0;
		var innertion = 5;
		var innertionFade = 0.1;
		var left = false;
		var right = true;
		var currentItem = $( contentItems ).index( $( 'div.item.active' ) );
		if( generalBlock.length > 0 )
		{
			objectsCount = contentItems.length;
			if( objectsCount > 0 )
			{
				$( 'a.rally_home:not(.active,.no_result)' ).mouseenter(
					function( event )
					{
						$( this ).animate( { 'opacity': 1 }, 100 );
					}
				);
				$( 'a.rally_home:not(.active,.no_result)' ).mouseleave(
					function( event )
					{
						$( this ).animate( { 'opacity': 0.4 }, 100 );
					}
				);
				$.each( contentItems,
					function( index, item )
					{
						contentWidth += $( item ).width() + 10;
						$( item ).mouseenter(
							function( event )
							{
								if( !$( this ).hasClass( 'not_clickable' ) )
								{
									if( currentItem != index )
									{
										$( this ).find( 'a:not(.active,.no_result)' ).animate( { 'opacity': 1 }, 100 );
									}
								}
							}
						);
					
						$( item ).mouseleave(
							function( event )
							{
								if( !$( this ).hasClass( 'not_clickable' ) )
								{
									if( currentItem != index )
									{
										$( this ).find( 'a:not(.active,.no_result)' ).animate( { 'opacity': 0.4 }, 100 );
									}
								}
							}
						);
					}
				);

				if( contentWidth > generalWidth )
				{
					
					function updatingScroller()
					{
						if( mouseState.clicked )
						{
							speed += ( mouseState.currentMouseX - mouseState.lastMouseX ) / 10;
						}
						if( currentLeft != 0 && !left )
						{
							$( controlLeft ).fadeIn( 400 );
							left = true;
						}
						if( currentLeft == 0 && left )
						{
							$( controlLeft ).fadeOut( 400 );
							left = false;
							keys.left = false;
						}
						
						if( generalWidth - currentLeft != contentWidth && !right )
						{
							$( controlRight ).fadeIn( 400 );
							right = true;
						}
						if( generalWidth - currentLeft == contentWidth && right )
						{
							$( controlRight ).fadeOut( 400 );
							right = false;
							keys.right = false;
						}
						
						if( keys.right && generalWidth - currentLeft <= contentWidth )
						{
							speed = -innertion;
						}
						if( keys.left && currentLeft != 0 )
						{
							speed = innertion;
						}
						
						currentLeft += speed;
						if( currentLeft > 0 )
						{
							currentLeft = 0;
						}
						if( generalWidth - currentLeft > contentWidth )
						{
							currentLeft = - ( contentWidth - generalWidth );
						}
						
						$( contentBlock ).css( 'left', currentLeft );
						
						if( speed != 0 )
						{
							if( speed < 0 )
							{
								speed += innertionFade;
							}
							else
							{
								speed -= innertionFade;
							}
							if( Math.abs( speed ) < 0.1 )
							{
								speed = 0;
							}
						}
					}
					
					setInterval( updatingScroller, 20 );
					
					$( controlRight ).fadeIn( 400 );
					
					$( controlLeft ).mousedown(
						function( event )
						{
							keys.left = true;
							return false;
						}
					);
			
					$( controlRight ).mousedown(
						function( event )
						{
							keys.right = true;
							return false;
						}
					);
					
					$( controlLeft ).mouseup(
						function( event )
						{
							keys.left = false;
							return false;
						}
					);
			
					$( controlRight ).mouseup(
						function( event )
						{
							keys.right = false;
							return false;
						}
					);
					
					$( generalBlock ).mousedown(
						function( event )
						{
							mouseState.firstMouseX = event.pageX;
							mouseState.lastMouseX = event.pageX;
							mouseState.currentMouseX = event.pageX;
							mouseState.shouldClick = true;
							mouseState.clicked = true;
							return false;
						}
					);
					$( generalBlock ).mouseup(
						function( event )
						{
							mouseState.clicked = false;
							mouseState.lastMouseX = event.pageX;
							mouseState.currentMouseX = event.pageX;
							return false;
						}
					);
					
					$( generalBlock ).mousemove(
						function( event )
						{
							mouseState.lastMouseX = mouseState.currentMouseX;
							mouseState.currentMouseX = event.pageX;
							if( mouseState.shouldClick )
							{
								if( Math.abs( mouseState.currentMouseX - mouseState.firstMouseX ) > mouseDisturion )
								{
									mouseState.shouldClick = false;
								}
							}
						}
					);
					
					$( generalBlock ).mouseleave(
						function( event )
						{
							mouseState.clicked = false;
						}
					);
					
					$( contentItems ).find( 'a' ).click(
						function( event )
						{
							return false;
						}
					);
					
					$( contentItems ).find( 'a' ).mouseup(
						function( event )
						{
							if( unclickable )
							{
								return false;
							}
							else
							{
								if( mouseState.shouldClick && !$( this ).parent().hasClass( 'not_clickable' ) )
								{
									if( $( this ).attr( 'target' ) == '_blank' )
									{
										window.open( $( this ).attr( 'href' ) );
									}
									else
									{
										window.open( $( this ).attr( 'href' ), '_self' );
									}
								}
								else
								{
									return false;
								}
							}
						}
					);
					
				}
				else
				{
					$( contentBlock ).width( contentWidth + 10 );
					$( contentBlock ).css( 'margin', '0 auto' );
					$( contentItems ).find( 'a' ).click(
						function( event )
						{
							if( $( this ).parent().hasClass( 'not_clickable' ) )
							{
								return false;
							}
						}
					);
				}
			}
		}
	}
);

//-----------------------faq accordion----------------------------
$( document ).ready(
	function()
	{
		var generalBlock = $( 'div.class_faq' );
		var headerBlocks = $( 'div.class_faq div.attribute_description h3' );
		var contentBlocks = $( 'div.class_faq div.attribute_description div.faq_element' );
		var currentBlock = -1;
		if( generalBlock.length > 0 && headerBlocks.length == contentBlocks.length )
		{
			$( contentBlocks ).slideUp( 300 );
			$.each( headerBlocks,
				function( index, item )
				{
					$( item ).click(
						function( event )
						{
							if( currentBlock == index )
							{
								$( contentBlocks[currentBlock] ).slideUp( 300 );
								$( headerBlocks[currentBlock] ).removeClass( 'active' );
								currentBlock = -1;
							}
							else
							{
								$( contentBlocks[index] ).slideDown( 300 );
								$( headerBlocks[index] ).addClass( 'active' );
								$( contentBlocks[currentBlock] ).slideUp( 300 );
								$( headerBlocks[currentBlock] ).removeClass( 'active' );
								currentBlock = index;
							}
						}
					);
				}
			);
		}
	}
);

//-----------------------drivers gallery----------------------------
function set_drivers_gallery()
	{
		var generalBlock = $( 'div.drivers_folder' );
		var galleryItems = $( 'div.drivers_folder div.drivers_gallery_preview div.drivers_gallery_items div.item' );
		var controlLeft = $( 'div.drivers_folder div.drivers_gallery_preview div.drivers_gallery_items a.drivers_previous' );
		var controlRight = $( 'div.drivers_folder div.drivers_gallery_preview div.drivers_gallery_items a.drivers_next' );
		var currentItem = 0;
		if( galleryItems.length > 0 )
		{
			$( controlLeft ).live('click',
				function( event )
				{
					$( galleryItems[ currentItem ] ).fadeOut( 300 );
					currentItem--;
					if( currentItem < 0 )
					{
						currentItem = galleryItems.length - 1;
					}
					$( galleryItems[ currentItem ] ).fadeIn( 300 );
					event.preventDefault();
				}
			);
			$( controlRight ).live('click',
				function( event )
				{
					$( galleryItems[ currentItem ] ).fadeOut( 300 );
					currentItem++;
					if( currentItem >= galleryItems.length )
					{
						currentItem = 0;
					}
					$( galleryItems[ currentItem ] ).fadeIn( 300 );
					event.preventDefault();
				}
			);
		}
	}

//-------------------select replacer------------------------------
$( document ).ready(
	function()
	{
    set_drivers_gallery();
		var selectors = $( 'div.form_row.select select' );
		var currentSelectedItem = 0;
		var currentStatus = false;
		if( selectors.length > 0 )
		{
			$( selectors ).hide();
			var replacedSelect = $( '<div id="select_replace"><span class="selection_head"><span class="current_value"></span><span class="selection_arrow"></span></span></div>' );
			$( selectors ).parent().append( replacedSelect );
			replacedSelect = $( '#select_replace' );
			var replacedSelectHead = $( '#select_replace span.selection_head' );
			var ulList = $( '<ul class="selection_list"></ul>' );
			
			$.each( $( selectors ).find( 'option' ),
				function( index, item )
				{
					if( index == $( selectors ).val() )
					{
						$( replacedSelectHead ).children( 'span.current_value' ).text( $( item ).text() + " *" );
					}
					$( ulList ).append( $( '<li>' + '<a href="' + $( item ).attr( 'value' ) + '">' + $( item ).text() + '</a>' + '</li>' ) );
				}
			);
			
			$( replacedSelect ).append( ulList );
			
			var replacedSelectContent = $( '#select_replace ul' );
			
			$( replacedSelectHead ).click(
				function( event )
				{
					if( !currentStatus )
					{
						$( replacedSelectContent ).fadeIn( 100 );
						currentStatus = true;
					}
					else
					{
						$( replacedSelectContent ).fadeOut( 100 );
						currentStatus = false;
					}
					return false;
				}
			);

			
			$.each( $( replacedSelectContent ).find( 'li a' ),
				function( index, item )
				{
					$( item ).click(
						function( event )
						{
							$( replacedSelectHead ).children( 'span.current_value' ).text( $( item ).text() );
							currentSelectedItem = index;
							$( selectors ).val( index );
							$( replacedSelectContent ).fadeOut( 100 );
							currentStatus = false;
							return false;
						}
					);
				}
			);
			
			$( replacedSelect ).mouseleave(
				function( event )
				{
					$( replacedSelectContent ).fadeOut( 100 );
					currentStatus = false;
				}
			);
			
		}
	}
);

//----------------checkbox replacer-------------------------
$( document ).ready(
	function()
	{
		var checkboxBlock = $( 'div.form_row.checkbox input[type="checkbox"]' );
		var checkboxBlockReplaced = $( checkboxBlock ).siblings( 'span.checkbox' );
		if( checkboxBlock.length > 0 )
		{
			$( checkboxBlockReplaced ).click(
				function( event )
				{
					if( $( checkboxBlockReplaced ).hasClass( 'checked' ) )
					{
						$( checkboxBlockReplaced ).removeClass( 'checked' );
						$( checkboxBlock ).attr( 'checked', false );
					}
					else
					{
						$( checkboxBlockReplaced ).addClass( 'checked' );
						$( checkboxBlock ).attr( 'checked', true );
					}
					return false;
				}
			);
			
			$( checkboxBlockReplaced ).mousedown(
				function( event )
				{
					return false;
				}
			);
			
			$( checkboxBlockReplaced ).mouseup(
				function( event )
				{
					return false;
				}
			);
		}
	}
);

//----------------------------content action button--------------------------
$( document ).ready(
	function()
	{
		var actionForm = $( 'form.contact_us_form div.content-action input.defaultbutton' );
		var actionButtonLink = $( 'div.content-action a.submit_button' );
		if( actionButtonLink.length > 0 )
		{
			$( actionButtonLink ).click(
				function( event )
				{
					var text_inputs = $( 'form.contact_us_form input[type="text"], form.contact_us_form textarea' );
					$.each( text_inputs,
						function( index, item )
						{
							if( $( this ).val() == $( this ).siblings( 'a.default_value' ).attr( 'rel' ) )
							{
								$( this ).val( "" );
							}
						}
					);
					$( actionForm ).click();
					return false;
				}
			);
		}
		
	}
);

//-------------------default value-----------------------------
$( document ).ready(
	function()
	{
		var text_inputs = $( 'form.contact_us_form input[type="text"], form.contact_us_form textarea' );
		//var textarea_inputs = $( 'form.contact_us_form textarea' );
		if( text_inputs.length )
		{
			$.each( text_inputs,
				function( index, item )
				{
					if( $( this ).val() == "" )
					{
						$( this ).val( $( this ).siblings( 'a.default_value' ).attr( 'rel' ) );
					}
					$( item ).focus(
						function( event )
						{
							if( $( this ).val() == $( this ).siblings( 'a.default_value' ).attr( 'rel' ) )
							{
								$( this ).val( "" );
							}
						}
					);
					$( item ).blur(
						function( event )
						{
							if( $( this ).val() == "" )
							{
								$( this ).val( $( this ).siblings( 'a.default_value' ).attr( 'rel' ) );
							}
						}
					);
				}
			);
		}
	}
);

//------------------------partner-car----------------------------
$( document ).ready(
	function()
	{
		//starting animation for partner-car
		var partnerCarDetail = $( 'div.car_view a.partner_car_detail' );
		if( partnerCarDetail.length > 0 )
		{
			$.each( partnerCarDetail,
				function( index, item )
				{
					setTimeout(
						function()
						{
							$( item ).find( 'img' ).animate( { 'width': 42, 'height': 42, 'top': 0, 'left': 0  }, 700,
								function()
								{
									$( item ).addClass( 'bg' );
									$( this ).remove();
								}
							);
						},
						1000 + ( 2 * parseInt( $( item ).css( 'left' ) ) )
					);
				
					$( item ).mouseenter(
						function( event )
						{
							//$( this ).find( 'img' ).animate( { 'opacity': 1 }, 100 );
							$( this ).find( 'span.car_detail_description' ).show();
						}
					);
			
					$( item ).mouseleave(
						function( event )
						{
							//$( this ).find( 'img' ).animate( { 'opacity': 0.5 }, 100 );
							$( this ).find( 'span.car_detail_description' ).hide();
						}
					);
				}
			);
		}
	}
);
//-----------------------------countdown----------------------
$( document ).ready(
	function()
	{
		var teaser_countdown = $('.class-teaser_countdown .content table');
		var teaser_countdown_dakar = $('.class-teaser_countdown_dakar .content table');
		if( teaser_countdown.length > 0 )
		{
			$.each( teaser_countdown,
				function( key, val )
				{
					var date_to = new Date(rally_to_timestamp[key]*1000);
					$(val).find('tr.numbers').countdown({until: date_to,
                      layout: '<td>{dn}</td><td>:</td><td>{hn}</td><td>:</td><td>{mn}</td><td>:</td><td>{sn}</td>'});
				}
			);
		}
		if( teaser_countdown_dakar.length > 0 )
		{
			$.each( teaser_countdown_dakar,
				function( key, val )
				{
					var date_to = new Date( dakar_to_timestamp[key] * 1000 );
					$( val ).find('tr.numbers').countdown({ 'until': date_to,
						'layout': '<td>{dn}</td><td>:</td><td>{hnn}</td><td>:</td><td>{mn}</td>'});
				}
			);
		}
	}
);
//-----------------------------countdown dakar----------------------
$( document ).ready(
	function()
	{
    if ($('.class-teaser_countdown .content table').length > 0)
      {
        $.each($('.content table'), function(key,val)
          {
            var date_to = new Date(rally_to_timestamp[key]*1000);
            $(val).find('tr.numbers').countdown({until: date_to,
                      layout: '<td>{dn}</td><td>:</td><td>{hn}</td><td>:</td><td>{mn}</td><td>:</td><td>{sn}</td>'});
          });
      }
	}
);
//--------------------------jscrollpane------------------------
$( document ).ready(
	function()
	{
	     if ( $(".nxc-facebook-comments-popup-position").parents('.homepage_content_item:hidden').length != 0)
	       {
	         var hiddenParentItems = $(".nxc-facebook-comments-popup-position").parents('.homepage_content_item:hidden').show();
         }
        var sliders = $(".nxc-facebook-comments-popup-position");
        $.each(sliders,function(key,val)
          {
            $(val).jScrollPane({scrollbarWidth:18, showArrows:true});
          });
      if ( $(hiddenParentItems).length != 0 )
        {
          hiddenParentItems.hide();
        }
  }
);
//------------map image hotspots---------------
$(document).ready(
  function()
    {
      var icons = $('.map_image .map_icon');
      if (icons.length != 0)
        {
          $.each(icons,
            function(key,value)
              {
                var offset_x = $(value).css('left');
                var offset_y = $(value).css('top');
                var point_left = true;
                var point_up = true;
                if ((parseInt(offset_x) +230+60) > (650))
                  point_left = false;
                if ((parseInt(offset_y) + 230+30) > (900))
                  point_up = false;
                if (point_left && point_up)
                  $(value).find('.description_container').prepend('<div class="pointer_left_up"/>').css('top','11px').css('left','33px').find('.descr_block').css('margin-top','-10px');
                if (!point_left && point_up)
                  $(value).find('.description_container').prepend('<div class="pointer_right_up"/>').css('top','11px').css('right',parseInt($(value).find('.icon_image').css('width'))/2).find('.descr_block').css('margin-top','-10px');
                if (point_left && !point_up)
                  $(value).find('.description_container').append('<div class="pointer_left_down"/>').css('bottom',10).css('left','33px');
                if (!point_left && !point_up)
                  $(value).find('.description_container').append('<div class="pointer_right_down"/>').css('bottom',10).css('right',parseInt($(value).find('.icon_image').css('width'))/2);

                $(value).find('.hover_icon').hover(
                  function()
                    {
                      $(value).find('.description_container').fadeIn();
                      $(value).toggleClass('active');
                    },
                  function()
                    {
                      $(value).find('.description_container').fadeOut();
                      $(value).toggleClass('active');
                    });
              });
        }
    }
  );

