jQuery.noConflict();
jQuery(document).ready(function(){
    
    jQuery('.validate').validate();
    jQuery.ifixpng('/i/mixmax.ru/spacer.gif');
    jQuery('.png, img[src$=".png"]').ifixpng();
    
    jQuery('a.flash').each(function(){
        jQuery(this).replaceWith('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+jQuery(this).attr('width')+'" height="'+jQuery(this).attr('height')+'"><param name="movie" value="'+jQuery(this).attr('href')+'" /><param name="quality" value="high" /><embed src="'+jQuery(this).attr('href')+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+jQuery(this).attr('width')+'" height="'+jQuery(this).attr('height')+'"></embed></object>');
    });
    
    // Школа красоты
    
    jQuery('ul.paging').quickPager({pageSize:2, pagerLocation:'before'});
    if (jQuery.browser.msie) {
        jQuery('ul.paging li:nth-child(even)').css('margin-left', '85px');
        jQuery('ul.simplePagerNav').css('margin-left', '460px');
    }
    /*jQuery('.imghover').hover(function(){
        jQuery(this).attr('src', jQuery(this).attr('src')+'&highlight=1');
    }, function(){
        jQuery(this).attr('src', jQuery(this).attr('src').replace(/&highlight=1/, ''));
    });*/
    
    // Голосование
    
    jQuery('.vote').click(function(){
        
        if (!jQuery('#votediv').length) {
            jQuery('<div id="votediv" title="Голосование"><center><br /><img src="/i/mixmax.ru/loading.gif" /></center></div>').dialog({width:400});
        }
        
        var order = '';
        jQuery('a.vote').each(function(){
            order += '&order[]='+jQuery(this).attr('i');
        });
         
        jQuery.get('/i/vote.php?name='+jQuery(this).attr('i')+order, function(data){
            jQuery('#votediv').html(data).dialog('open');
		});
        
        return false;
        
    });
    
    jQuery('#vote_submit').click(function(){
        var answer = jQuery('input[name=answer]:checked').val();
        if (answer) {
            var height = jQuery('#div_vote').height();
            jQuery('#div_vote').html('<center><img src="/i/mixmax.ru/ajaxload.gif" /></center>').height(height).load('/vote/do.'+answer+'.html');
    	}
    });
	
    jQuery('#a_vote_comment').click(function(){
        jQuery('#div_vote_comment').dialog('open');
    });

    jQuery('#div_vote_comment').dialog({
        autoOpen:false,
        width:440,
        buttons:{
            'Отправить':function(){
                if (jQuery(this).find('form').valid()) {
                    jQuery(this).find('form').submit();
                }
            }
        }
    });
    
    // Комментарии в разделах
    
    jQuery('#a_contents_comment').click(function(){
        jQuery('#div_contents_comment').dialog('open');
    });

    jQuery('#div_contents_comment').dialog({
        autoOpen:false,
        width:440,
        buttons:{
            'Отправить':function(){
                if (jQuery(this).find('form').valid()) {
                    jQuery(this).find('form').submit();
                }
            }
        }
    });
    
    // Подстказывалки в полях
    
    jQuery('.hint').focus(function(){
        if (jQuery(this).css('font-style')=='italic') {
            jQuery(this).css('font-style', '');
            jQuery(this).css('color', '');
            jQuery(this).attr('val_old', jQuery(this).val());
            jQuery(this).val('');
        }
    });
    
    jQuery('.hint').blur(function(){
        if (!jQuery(this).val().length) {
            jQuery(this).css('font-style', 'italic');
            jQuery(this).css('color', '#ccc');
            jQuery(this).val(jQuery(this).attr('val_old'));
        }
    });
    
});

jQuery.validator.addMethod('phone', function(ph, element) {
    if (this.optional(element)) {
        return true;
    }
    var stripped = ph.replace(/[\s()+-]|ext\.?/gi, '');
    // 6 is the minimum number of numbers required
    return ((/\d{7,}/i).test(stripped));
}, 'Пожалуйста, введите корректный номер телефона.');
