// JavaScript Document

$(function(){
    
    
   $("#news-top").hover(function(){
      $("#news-top > div").fadeIn(200);
   },function(){
      $("#news-top > div").fadeOut(200);
   });
   
    $('div.country_in2').click(function(){
		if ($(this).find('a').attr('href')!="http://www.tourblogger.ru/tbg/operators/") {
			var h = $(this).find('a').attr('href');
			document.location.href = h ;
		}
	});
	$('#banner_megapolus').click(function(){
		window.open("http://online.megapolus-tours.ru/masterwebstandard/Extra/QuotedDynamic.aspx");

		});
    /* Бегущая строка */
	$('ul#crow_line').liScroll({travelocity: 0.05});
		
	$('div#country_all').click(function(){

			var h = $(this).find('a').attr('href');
			document.location.href = h ;
		
	});

	if (
		(document.location.href=="http://www.surgut-kurort.ru/index.php?menu_2=7&content=26&view=1") || 
		(document.location.href=="http://www.surgut-kurort.ru/index.php?menu_2=7&content=22&view=1") ||
		(document.location.href=="http://www.surgut-kurort.ru/index.php?menu_2=7&content=36&view=1") ||
		(document.location.href=="http://www.surgut-kurort.ru/index.php?menu_2=7&content=26&view=1") ||
		(document.location.href=="http://www.surgut-kurort.ru/index.php?menu_2=7&content=48&view=1") ||
		(document.location.href=="http://www.surgut-kurort.ru/?menu_2=7&content=26&view=1") || 
		(document.location.href=="http://www.surgut-kurort.ru/?menu_2=7&content=22&view=1") ||
		(document.location.href=="http://www.surgut-kurort.ru/?menu_2=7&content=36&view=1") ||
		(document.location.href=="http://www.surgut-kurort.ru/?menu_2=7&content=26&view=1") ||
		(document.location.href=="http://www.surgut-kurort.ru/?menu_2=7&content=48&view=1") ||
		(document.location.href=="http://www.surgut-kurort.ru/index.php?view=sanatories&price=71") ||
		(document.location.href=="http://www.surgut-kurort.ru/?view=sanatories&price=71") ||
        (document.location.href=="http://www.surgut-kurort.ru/index.php?menu_2=7&content=26") ||
        (document.location.href=="http://www.surgut-kurort.ru/?menu_2=7&content=26")
	) {
		$("div.content_2").css("width","995px");
		$("div#right").css("display","none");
		$("div.content_2>iframe").css("width",985).css("height",600)
	};
    /*
    if(document.location.href.indexOf('?menu_2=7') + 1) {
        $("div.content_2").css("width","995px");
		$("div#right").css("display","none");
		$("div.content_2>iframe").css("width",985).css("height",600)
            
    };
    */
	if (
		(document.location.href=="http://www.surgut-kurort.ru/index.php?option=com_content&task=view&id=911&Itemid=202") 
	) {
		document.location.href="http://www.surgut-kurort.ru/"
	};

	
	
	$('div#tbg_1').click(function(){
		window.open("http://www.tourblogger.ru/tbg/agencies/","win");
	});
	
	$('div#tbg_2').click(function(){
		window.open("http://tourblogger.ru/tbg/agencies/284","win");
	});

	$('#jsddm li').hover(  
        function () {  
				
             $('ul', this).css('visibility','visible');  
   
         },   
         function () {  
             
             $('ul', this).css('visibility','hidden');           
         }  
     );  
	 $('#mmm2 li').hover(  
        function () {  
				
             $('div', this).css('visibility','visible');  
   
         },   
         function () {  
             
             $('div', this).css('visibility','hidden');           
         }  
     );
 
	$('ul#fiz li').toggle(  
        function () {  
             if (loc=$(this).find('a').attr('href')=='#') {
				$('ul', this).slideDown(180);	
			 } else {
				 var loc=$(this).find('a').attr('href');
				 document.location.href=loc;
			 }
   
         },   
         function () {  
		 if ($(this).find('div#slide_ul')) {
             $('ul', this).slideUp(180);          
		 }
         }  
     ); 
	 $('ul#on-line li').toggle(  
        function () {  
             if (loc=$(this).find('a').attr('href')=='#') {
				$('ul', this).slideDown(180);	
			 } else {
				 var loc=$(this).find('a').attr('href');
				 window.open(loc);
			 }
         },   
         function () {  
		 if ($(this).find('div#slide_ul')) {
             $('ul', this).slideUp(180);          
		 }
         }  
     ); 
	
	$('ul#san li:has(a)').toggle(  
        function () {  
             if (loc=$(this).find('a').attr('href')=='#') {
				$('ul', this).slideDown(180);	
			 } else {
				 var loc=$(this).find('a').attr('href');
				 document.location.href=loc;
			 }
   
         },   
         function () {  
		 if ($(this).find('div#slide_ul')) {
             $('ul', this).slideUp(180);          
		 }
         }  
     );  
	 
	 
	$('a.tur').cluetip({
		splitTitle: '|',
		leftOffset: -20,
		
	});
		var i=0;
		if (i==0) {
			$('#animate').animate({opacity: '.0'},1);
			i=1;
		};
 		 $('#animate').mouseover(function()
			{
				$(this).animate({opacity: '.999'},300);
			})
		.mouseout(function()
			{
				$(this).animate({opacity: '.0'},300);
			});

		$('#menu_2>ul#mmm2>li>a').mouseover(function()
			{
				$(this).stop();
				$(this).animate(
				{
					backgroundPosition: '0px -35px',
				},200);
			})
		.mouseout(function()
			{
				$(this).stop();
				$(this).animate({backgroundPosition: '0px 0px'},300);
			});


    /* -- IMAGE GALLERY -- */

		$("a[rel^='prettyPhoto']").prettyPhoto({
		  animationSpeed:'slow',
          slideshow:3000,
          autoplay_slideshow: false,
          overlay_gallery: false
          });
        $("a[href^='images/photos/19']").prettyPhoto({
		  animationSpeed:'slow',
          slideshow:3000,
          autoplay_slideshow: true,
          overlay_gallery: false
          });

         $("a[rel^='pP']").prettyPhoto({
			  
              autoplay_slideshow: false,
              overlay_gallery: false
              });

    /* -- /IMAGE GALLERY -- */
    });

$(document).ready(function() {
	//Speed of the slideshow
	var speed = 5000;
	//You have to specify width and height in #slider CSS properties
	//After that, the following script will set the width and height accordingly
	$('#mask-gallery, #gallery li').width($('#headerslider').width());
	$('#gallery').width($('#headerslider').width() * $('#gallery li').length);
	$('#mask-gallery, #gallery li, #matterwrap, #matter li').height($('#headerslider').height());
	//Assign a timer, so it will run periodically
	var run = setInterval('newsscoller(0)', speed);
		$('#gallery li:first, #matter li:first').addClass('selected');

	//Next Slide by calling the function
	$('#btn-next').click(function () {
		newsscoller(0);
		return false;
	});

	//Previous slide by passing prev=1
	$('#btn-prev').click(function () {
		newsscoller(1);
		return false;
	});

	//Mouse over, pause it, on mouse out, resume the slider show
	$('#headerslider').hover(
		function() {
			clearInterval(run);
		},
		function() {
			run = setInterval('newsscoller(0)', speed);
		}
	);

});
function newsscoller(prev) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
	var current_excerpt = $('#matter li.selected').length ? $('#matter li.selected') : $('#matter li:first');

	//if prev is set to 1 (previous item)
	if (prev) {

		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
		var next_excerpt = (current_excerpt.prev().length) ? current_excerpt.prev() : $('#matter li:last');

	//if prev is set to 0 (next item)
	} else {

		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
		var next_excerpt = (current_excerpt.next().length) ? current_excerpt.next() : $('#matter li:first');
	}

	//clear the selected class
	$('#matter li, #gallery li').removeClass('selected');

	//reassign the selected class to current items
	next_image.addClass('selected');
	next_excerpt.addClass('selected');

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image, 800);
	$('#matterwrap').scrollTo(next_excerpt, 800);

}

