//votes 
$(function(){
 $('.hover-star').rating({
  focus: function(value, link){
    var tip = $('#hover-test');
    tip[0].data = tip[0].data || tip.html();
    tip.html(link.title || 'value: '+value);
  },
  blur: function(value, link){
    var tip = $('#hover-test');
    $('#hover-test').html(tip[0].data || '');
  },
  callback: function(value, link){$('#ratcl').show();if (link.title=='') {$('#ratcl').hide();}}
 });
});

function showw()  
{  
	$('#loading5').show();
	$('#upd').hide();

	$.ajax({  
		url: "puls.php?are=chat&n=main",  
		cache: false,  
		success: function(html){  
			$('.overview').html(html);  
		}  
	});  
	
	$('#loading5').bind('ajaxComplete', function(){ $('#loading5').hide();$('#upd').show(); });		
} 
	
$(document).ready(function(){
setInterval('showw()',10000);  

$('#oldupload').hide();
$('#scrollbar1').tinyscrollbar();	

$('#radioclick').click(function(){
	$('#radio').toggle();
	$('#radio').load('/radio.html');   
});

$('#olduploadbut').click(function(){
	$('#oldupload').toggle();
});


function drop_confirm(){
return confirm('Удаление записи. Уверены?');
}
function drop_confirm2(){
return confirm2('Будут удалён комментарий и ветка комментариев, относящаяся к нему. Уверены?');
}
//чат 
  var options = { 
	target: ".overview",
	notsuccess: errorAjax3,
	resetForm: true,
	timeout: 20000 // тайм-аут
  };
  var options2 = { 
	target: ".newrat",
	notsuccess: errorAjax2,
	resetForm: true,
	timeout: 20000 // тайм-аут
  };  

  $('#myForm2').submit(function() { 
	$('#loading5').show();
	$('#upd').hide();
	$(this).ajaxSubmit(options); 
	$('#loading5').bind('ajaxComplete', function(){ $('#loading5').hide();$('#upd').show(); });		
	return false;
  }); 
  
  $('#formrat').submit(function() { //рейтинг 
	$('#loading6').show();
	$(this).ajaxSubmit(options2); 
	$('#loading6').bind('ajaxComplete', function(){ $('#loading6').hide();});		
	return false;
  });  
 	function errorAjax2(statusText) {
	alert('Хм... Ошибка. Ваша оценка скорее всего не засчиталась. Погодите пинутку');
	$('#loading6').show();
	$('.newrat').load('ajaxrating.php?ina=send');      
	$('#loading6').bind('ajaxComplete', function(){ $('#loading6').hide(); });					
	} 
  
	function errorAjax3(statusText) {
	alert('Хм... Сообщение скорее всего отправилось. Погодите пинутку');
	$('#loading').show();
	$('.overview').load('puls.php?are=chat');      
	$('#loading5').bind('ajaxComplete', function(){ $('#loading5').hide(); });					
	}
	
	$('#whoos').click(function(){
		$('#usonlinelist').toggle(500);
		$('#loading5').show();
		$('#upd').hide();
		$('#usonlinelist').load('who.php');    
		$('#loading5').bind('ajaxComplete', function(){ $('#loading5').hide();$('#upd').show(); });
	});		
	
	$('#upd').click(function(){
		$('#upd').hide();
		$('#loading5').show(); 	
		$('.overview').load('puls.php?are=chat&n=main'); 
		$('#loading5').bind('ajaxComplete', function(){ $('#loading5').hide();$('#upd').show(); });
	});		
});
	
window.name='main';


if(!$.browser.msie) {
$().ready(function() {
  $('#ex3b').jqmAddTrigger('a.ex3bTrigger');
  $('#ex3b').jqm({
    trigger: 'a.ex3bTrigger',
    ajax: 'puls.php',
    target: 'div.jqmAlertContent',    
	onHide: function(h) { 
      h.w.fadeOut(888);
    },
	onShow: function(h) { 
      h.w.fadeIn(888);
    },
    overlay: 0
    });
  
  // Close Button Highlighting. IE doesn't support :hover. Surprise?
  if($.browser.msie) {
  $('div.jqmAlert .jqmClose')
  .hover(
    function(){ $(this).addClass('jqmCloseHover'); }, 
    function(){ $(this).removeClass('jqmCloseHover'); });
  }
  jQuery('#loading4').bind('ajaxComplete', function(){ jQuery('#loading4').hide(); });
    
});}
   jQuery(document).ready(function(){
	jQuery('.style2 *').tooltip({delay: 0, showURL: false});
	jQuery('#whoon').tooltip({delay: 0, showURL: false});
	jQuery('.when *').tooltip({delay: 0, showURL: false});
	jQuery('#when').tooltip({delay: 0, showURL: false});
});



function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        '/imagecube.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('image', xml).each(function(i) {
		//сперва разделяем и впихнем в 1 переменную первую часть jQuery(this).text(), до |
		//а во 2 переменную вторую часть , что после |

		var text = jQuery(this).text();  
		pos = text.indexOf("=");
		url1 = text.substring(0, pos);
		url2 = text.substring(pos+1);

        carousel.add(first + i, mycarousel_getItemHTML(url1, url2));
    });
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url1,url2)
{
    return '<a href="/plug.php?e=gal&pic=' + url2 + '"><img src="' + url1 + '" width="75" alt="" /></a>';
};

function mycarousel_initCallback(carousel, state) {
    if (state == 'init') $('#nodiv').show();
};
function mycarousel_itemLastInCallback(carousel, item, idx, state) {
    $('#nodiv').hide();
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.
        // itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        itemLoadCallback: mycarousel_itemLoadCallback,
        itemLastInCallback:   mycarousel_itemLastInCallback,
		buttonPrevHTML: null,
		scroll: 4,
		wrap: "circular"
    });
	
//gallery

// We only want these styles applied when javascript is enabled
$('div.content').css('display', 'block');

// Initially set opacity on thumbs and add
// additional styling for hover effect on thumbs
var onMouseOutOpacity = 0.67;
$('#thumbs ul.thumbs li, div.navigation a.pageLink').opacityrollover({
	mouseOutOpacity:   onMouseOutOpacity,
	mouseOverOpacity:  1.0,
	fadeSpeed:         'fast',
	exemptionSelector: '.selected'
});

// Initialize Advanced Galleriffic Gallery
var gallery = $('#thumbs').galleriffic({
	delay:                     2500,
	numThumbs:                 6,
	preloadAhead:              12,
	enableTopPager:            false,
	enableBottomPager:         false,
	imageContainerSel:         '#slideshow',
	controlsContainerSel:      '#controls',
	captionContainerSel:       '#caption',
	loadingContainerSel:       '#loading',
	renderSSControls:          true,
	renderNavControls:         true,
	playLinkText:              'Play Slideshow',
	pauseLinkText:             'Pause Slideshow',
	prevLinkText:              '&lsaquo; Previous Photo',
	nextLinkText:              'Next Photo &rsaquo;',
	nextPageLinkText:          'Next &rsaquo;',
	prevPageLinkText:          '&lsaquo; Prev',
	enableHistory:             false,
	enableKeyboardNavigation:  false,
	autoStart:                 false,
	syncTransitions:           true,
	defaultTransitionDuration: 0,
	onSlideChange:             function(prevIndex, nextIndex) {
		// 'this' refers to the gallery, which is an extension of $('#thumbs')
		this.find('ul.thumbs').children()
			.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
			.eq(nextIndex).fadeTo('fast', 1.0);

		// Update the photo index display
		this.$captionContainer.find('div.photo-index')
			.html('Photo '+ (nextIndex+1) +' of '+ this.data.length);
	},
	onPageTransitionOut:       function(callback) {
		this.fadeTo('fast', 0.0, callback);
	},
	onPageTransitionIn:        function() {
		var prevPageLink = this.find('a.prev').css('visibility', 'hidden');
		var nextPageLink = this.find('a.next').css('visibility', 'hidden');
		
		// Show appropriate next / prev page links
		if (this.displayedPage > 0)
			prevPageLink.css('visibility', 'visible');

		var lastPage = this.getNumPages() - 1;
		if (this.displayedPage < lastPage)
			nextPageLink.css('visibility', 'visible');

		this.fadeTo('fast', 1.0);
	}
});

/**************** Event handlers for custom next / prev page links **********************/

gallery.find('a.prev').click(function(e) {
	gallery.previousPage();
	e.preventDefault();
});

gallery.find('a.next').click(function(e) {
	gallery.nextPage();
	e.preventDefault();
});
				
/****************************************************************************************/
});
