// Postbox Cookie
function setBoxes(){    
    $('.postbox').each(function(){
        if($.cookie($(this).attr('id'))=="closed")
        $(this).addClass('closed');
        else
        $(this).removeClass('closed');
    });
}
$(document).ready(function(){
// Go to Top
	$(window).scroll(function() {
		if($(this).scrollTop() != 0) {
			$('.gotop').fadeIn(500);	
		} else {
			$('.gotop').fadeOut(500);
		}
	});
	$('.gotop').click(function() {
		$('body,html').animate({scrollTop:0},800);
	});
// Search Form	
	var config = {    
		over: function(){
		$(this).find('.advanced-search-menu').fadeIn(200);
		$(this).find('.advanced-search-btn').addClass('hover');
		},
		interval:50,
		timeout: 100,  
		out: function(){
		$(this).find('.advanced-search-menu').fadeOut(100);
		$(this).find('.advanced-search-btn').removeClass('hover');
		}
	};
	$('#searchform .advanced-search').hoverIntent(config);	
// Slides	
	$('#slides').slides({
		preload: true,
		preloadImage: 'style/A6yafStyle/images/loading.gif',
		play: 5000,
		pause: 2500,
		hoverPause: true,
		generatePagination: false,
		slideEasing: 'easeOutExpo',
		slideSpeed: 500
	});
// Events
	var config = {    
		over: function(){
		$(this).find('.info').animate({bottom:0},300);
		},
		interval:20,
		timeout: 0,  
		out: function(){
		$(this).find('.info').animate({bottom:-120},300);
		}
	};
	$('ul#events li .thumb').hoverIntent(config);
// Updates Slides	
	$('#updates_slides').slides({
		preload: true,
		preloadImage: 'style/A6yafStyle/images/loading.gif',
		play: 5000,
		pause: 2500,
		hoverPause: true,
	});
// Category Slides	
	$('#category_slides').slides({
		preload: true,
		preloadImage: 'style/A6yafStyle/images/loading.gif',
		play: 5000,
		pause: 2500,
		hoverPause: true
	});
// Scrollable
	$('#scrollable').slides({
		preload: true,
		preloadImage: 'style/A6yafStyle/images/loading.gif',
		play: false,
		hoverPause: true,
		generatePagination: false,
	});
// Scrollbar
	$('#scrollbar').tinyscrollbar();
	
// Scrollbar
	$('#khaderscrollbar').tinyscrollbar();

// LiScroll
	$('#newsbar ul').liScroll({travelocity: 0.06});
// Colorbox
	$('.boxpopup').colorbox({opacity: 0.6});
// Photos
	var config = {    
		over: function(){
		$(this).find('.info').animate({bottom:0},300);
		},
		interval:20,
		timeout: 0,  
		out: function(){
		$(this).find('.info').animate({bottom:-100},300);
		}
	};
	$('#photos_block .photo').hoverIntent(config);
// Gallery
	var config = {    
		over: function(){
		$(this).find('.info').animate({bottom:0},300);
		},
		interval:20,
		timeout: 0,  
		out: function(){
		$(this).find('.info').animate({bottom:-120},300);
		}
	};
	$('ul.gallery li').hoverIntent(config);
// Vertical Ticker
	$('ul#reading-ticker').totemticker({
		row_height	:	'73px',
		next		:	'#reading .up',
		previous	:	'#reading .down',
		speed		:	300,
		mousestop	:	true,
	});
	$('ul#commenting-ticker').totemticker({
		row_height	:	'73px',
		next		:	'#commenting .up',
		previous	:	'#commenting .down',
		speed		:	300,
		mousestop	:	true,
	});
	$('ul#sending-ticker').totemticker({
		row_height	:	'73px',
		next		:	'#sending .up',
		previous	:	'#sending .down',
		stop		:	null,
		start		:	null,
		speed		:	300,
		mousestop	:	true,
	});
	$('#marbles_block ul').totemticker({
		row_height	:	'120px',
		next		:	'#marbles_block .up',
		previous	:	'#marbles_block .down',
		speed		:	400,
		mousestop	:	true,
	});
// Postbox
	var ismore = false, isheadtext = false;
	$('.postbox-head a').click(function(){
		ismore = true;
		return true;
	});
	$('.postbox-head h3').click(function(){
		isheadtext = true;
		return true;
	});
	$('.postbox .postbox-head').click(function(){
		if(isheadtext) { 
			isheadtext = false; return false;	
		}
		if(ismore) {
			ismore = false;
			document.location = $(this).find('h3 a').attr("href");
			return false;
		}
		$(this).find("h3").click(function() {
			return false;
		});
        $(this).parent().toggleClass('closed');
        if($(this).parent().hasClass('closed'))
        $.cookie($(this).parent().attr('id'), "closed", { expires: 1 });
        else
        $.cookie($(this).parent().attr('id'), "", { expires: 1 });
        });
        setBoxes();
// Search
	$('#search .search-form .search ul').superfish({ 
		delay:50, 
		speed:200
	});
// Post Author
	$('#post .author a.toggle').click(function(){
		$(this).parent().next('.author-details').slideToggle(100);
		$(this).toggleClass('show');
		return false;
	});
// Authors	
	$('#authors ul.authors li a.toggle').click(function(){
		$(this).parents().next('.author-details').slideToggle(100);
		$(this).toggleClass('show');
		return false;
	});
// Photographers	
	$('#photographers ul.photographers li a.toggle').click(function(){
		$(this).parents().next('.photographer-details').slideToggle(100);
		$(this).toggleClass('show');
		return false;
	});
// Breaking News	
	$('#breakingnews .handle').click(function(){
		$(this).parent().next('.inside').slideToggle(200);
		$(this).parents('#breakingnews').toggleClass('open');
		return false;
	});
// Tools	
	var config = {    
		over: function(){
		$(this).find('.dropbox').fadeIn(200);
		},
		interval:100,
		timeout: 200,  
		out: function(){
		$(this).find('.dropbox').fadeOut(100);
		}
	};
	$('ul#tools li').hoverIntent(config);
// Selectors
	$('ul#menu li:first-child').addClass('first');
	$('ul#events li:nth-child(3n)').addClass('nth-child');
	$('#morenews_block ul.morenews-block-list li:last-child').addClass('last');
	$('#affairs_block ul.affairs-list li:last-child').addClass('last');
	$('#newstab ul.newstab-list li:last-child').addClass('last');
	$('#news_list ul.news-list li:first-child').addClass('first');
	$('#news_list ul.news-list li:last-child').addClass('last');
	$('#slides .pagination li:last-child').addClass('last');
	$('#video_block .video .video-box:odd').addClass('odd');
	$('ul.gallery li:nth-child(3n)').addClass('nth-child');
	$('#categories ul.categories li:nth-child(3n)').addClass('nth-child');
	$('#related ul.related li:last-child').addClass('last-left');
	$('#post ul.post-photos li:last-child').addClass('last-left');
	$('#authors ul.authors li.list:last-child').addClass('last');
	$('#photographers ul.photographers li.list:last-child').addClass('last');
	$('#toolbar ul#tools li.money ul li:last-child').addClass('last-list');
	$('#photographer .photographer-albums ul li:nth-child(3n)').addClass('nth-child');
	$('#photographers .photographer-albums li:last-child').addClass('last-left');
	$('ul.posts li.post:last-child').addClass('last');
	$('ul.postlist li:last-child').addClass('last');
	$('#reports_block ul.reports-list li:last-child').addClass('last');
	$('#search ul.dropmenu li:first-child').addClass('first').append('<div class="right-corner"></div><div class="left-corner"></div>');
	$('#search ul.dropmenu li:last-child').addClass('last');
	$('#galleries ul.galleries li:nth-child(3n)').addClass('nth-child');
	$('#playlists ul.playlists li:nth-child(3n)').addClass('nth-child');
	$('ul.statsfloat li:last-child').addClass('last');
	$('#author_profile_mini ul.profile-stats li:last-child').addClass('last');
	$('#toolbar #newsbar ul.newsticker li:first-child').addClass('first');
/* Font Resizing */
	$('.tools-box ul.tools li.resizing-plus a').click(function(){
		var TextSize= parseInt($(this).attr("sizeText"))+2;
		if(TextSize <= 30 ){
		$(this).attr("sizeText",TextSize);
		$(".tools-box ul.tools li.resizing-negative a").attr("sizeText",TextSize);
		var lineHeightSize=  parseInt(TextSize)+10;
		$('#post .post-text p').animate({fontSize:TextSize+"px", lineHeight:lineHeightSize+"px"}, 300);
		}
		return false;
	});
		$('.tools-box ul.tools li.resizing-negative a').click(function(){
		var TextSize= parseInt($(this).attr("sizeText"))-2;
		if(TextSize >= 6 ){
		$(this).attr("sizeText",TextSize);
		$(".tools-box ul.tools li.resizing-plus a").attr("sizeText",TextSize);
		var lineHeightSize=  parseInt(TextSize)+10;
		$('#post .post-text p').animate({fontSize:TextSize+"px", lineHeight:lineHeightSize+"px"}, 300);
		}
		return false;
	});
// Comment Editor
	$('#comments .comment-form textarea.input').focus(function(){
		$(this).animate({height:100},200);
	});
// View
	$('#view .thumb').hover(function(){
		$(this).find("span").fadeTo("fast", 1);
	},
	function(){
		$(this).find("span").fadeTo("fast", 0);
	});
// Tipsy
	$('.south').tipsy({fade: true, gravity: 's'});
	$('.west').tipsy({fade: true, gravity: 'w'});
	$('.east').tipsy({fade: true, gravity: 'e'});
	$('.north').tipsy({fade: true, gravity: 'n'});
});
