<a href="javascript: void(0);" id="mode"<?php if ($_COOKIE['mode'] == 'grid') echo ' class="flip"'; ?>>Смена стиля</a>
<div id="loop" class="<?php if ($_COOKIE['mode'] == 'grid') echo 'grid'; else echo 'list'; ?>">Блок с изменяющимся стилем</div>
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
jQuery.noConflict();
(function($) {
$(function() {
/*** Dropdown menu ***/
var timeout = 200;
var closetimer = 0;
var ddmenuitem = 0;
function dd_open() {
dd_canceltimer();
dd_close();
var liwidth = $(this).width();
ddmenuitem = $(this).find('ul').css({'visibility': 'visible', 'width': liwidth});
ddmenuitem.prev().addClass('dd_hover').parent().addClass('dd_hover');
}
function dd_close() {
if(ddmenuitem) ddmenuitem.css('visibility', 'hidden').prev().removeClass('dd_hover').parent().removeClass('dd_hover');
}
function dd_timer() {closetimer = window.setTimeout(dd_close, timeout);
}
function dd_canceltimer() {
if (closetimer) {
window.clearTimeout(closetimer);
closetimer = null;
}
}
document.onclick = dd_close;
$('#dd > li').bind('mouseover', dd_open);
$('#dd > li').bind('mouseout', dd_timer);
$('#larr, #rarr').hide();
$('.slideshow').hover(
function(){
$('#larr, #rarr').show();
}, function(){
$('#larr, #rarr').hide();
}
);
/*** View mode ***/
if ( $.cookie('mode') == 'grid' ) {
grid_update();
} else if ( $.cookie('mode') == 'list' ) {
list_update();
}
$('#mode').toggle(
function(){
if ( $.cookie('mode') == 'grid' ) {
$.cookie('mode','list');
list();
} else {
$.cookie('mode','grid');
grid();
}
},
function(){
if ( $.cookie('mode') == 'list') {
$.cookie('mode','grid');
grid();
} else {
$.cookie('mode','list');
list();
}
}
);
function grid(){
$('#mode').addClass('flip');
$('#loop')
.fadeOut('fast', function(){
grid_update();
$(this).fadeIn('fast');
})
;
}
function list(){
$('#mode').removeClass('flip');
$('#loop')
.fadeOut('fast', function(){
list_update();
$(this).fadeIn('fast');
})
;
}
function grid_update(){
$('#loop').addClass('grid').removeClass('list');
$('#loop').find('.thumb img').attr({'width': '190', 'height': '190'});
$('#loop').find('.post')
.mouseenter(function(){
$(this)
.css('background-color','#ffffff')
.find('.thumb').hide()
.css('z-index','-1');
})
.mouseleave(function(){
$(this)
.css('background-color','#ffffff')
.find('.thumb').show()
.css('z-index','1');
});
$('#loop').find('.post').click(function(){
location.href=$(this).find('h2 a').attr('href');
});
$.cookie('mode','grid');
}
function list_update(){
$('#loop').addClass('list').removeClass('grid');
$('#loop').find('.post').removeAttr('style').unbind('mouseenter').unbind('mouseleave');
$('#loop').find('.thumb img').attr({'width': '290', 'height': '290'});
$.cookie('mode', 'list');
}
/*** Ajax-fetching posts ***/
$('#pagination a').live('click', function(e){
e.preventDefault();
$(this).addClass('loading').text('Подождите, подгружаемся...');
$.ajax({
type: "GET",
url: $(this).attr('href') + '#loop',
dataType: "html",
success: function(out){
result = $(out).find('#loop .post');
nextlink = $(out).find('#pagination a').attr('href');
$('#loop').append(result.fadeIn(300));
$('#pagination a').removeClass('loading').text('Предыдущие публикации');
if (nextlink != undefined) {
$('#pagination a').attr('href', nextlink);
} else {
$('#pagination').remove();
}
if ( $.cookie('mode') == 'grid' ) {
grid_update();
} else {
list_update();
}
}
});
});
/*** Misc ***/
$('#comment, #author, #email, #url')
.focusin(function(){
$(this).parent().css('border-color','#888');
})
.focusout(function(){
$(this).parent().removeAttr('style');
});
$('.rpthumb:last, .comment:last').css('border-bottom','none');
})
})(jQuery)
$weekdayNumber = $occurance == $maxOccurance
? "last"
: match($occurance) {
1 => "first",
2 => "second",
3 => "third",
4 => "fourth"
}
;