/**
 * Javascript: Scripts
 * 
 * Rapid Javascript development.
 * 
 * @package WP Framework
 * @subpackage JS
 */

;(function($){
	$(document).ready(function($){
$('.gallery-item a').attr({'rel':'colorbox'});
$('a[rel="colorbox"]').colorbox({slideshow:true,slideshowStart:'Play',slideshowStop: 'Stop'});
	});
	
	
})(jQuery);


jQuery(document).ready(function(){
// Initialize variables for tracking reserves
var reservesInit = 0,
pager = {},
anchors = [],
maxvis = 0;
slideTimeoutfeatured = 500;
jQuery("#featured")
.cycle({
    fx: "fade",
    timeout: 2000,
    speed: 0,
    pause: 1,
    cleartype: true,
    cleartypeNoBg: true,
    before: onBefore, // here maxvis needs to be set to the number of visible slide thumbnails
    maxvis: 7 
});

function onBefore(curr, next, opts) {
// this is only run once to setup the reserves
    if (reservesInit === 0) {
        pager = jQuery(opts.pager),
        anchors = pager.children(),
        maxvis = opts.maxvis;
        anchors.each(function(i, el) {
            if (i >= maxvis) {
                jQuery(el).addClass('resR');
        }
    });;
    reservesInit = 1;
}
// in case there are more slides than can fit in 5000px
if (pager.width() < anchors.length * anchors.eq(0).outerWidth(0)) {
    pager.css('width', anchors.length * anchors.eq(0).outerWidth(0));
}
var currSlide = opts.currSlide,
lastSlide = opts.lastSlide,
nextSlide = opts.nextSlide;
if (nextSlide === 0) {
    // reset all the anchors and reserves
    anchors.each(function(i, el) {
    var jObj = jQuery(el);
    if (jObj.hasClass('resL')) {
        jObj.removeClass('resL');
    }
    if (i >= maxvis) {
        jObj.addClass('resR');
    }
});
// slide the pager back into default position
pager.animate({
    left: 0
}, 'normal');
} else if (nextSlide === anchors.length - 1) {
// set anchors and reserves to their states for the last anchor
anchors.each(function(i, el) {
    var jObj = jQuery(el);
    if (jObj.hasClass('resR')) {
        jObj.removeClass('resR');
    }
    if (i <= nextSlide - maxvis) {
        jObj.addClass('resL');
    }
});
// slide the pager to display the last anchor
pager.animate({
left: (anchors.length - maxvis) * anchors.eq(0).outerWidth(true) * -1
}, 'normal');
} else {
if (currSlide < nextSlide) { // moving right (positive)
if (anchors.eq(nextSlide + 1).hasClass('resR')) {
anchors.eq(nextSlide + 1).removeClass('resR');
anchors.eq(nextSlide + 1 - maxvis).addClass('resL');
if (nextSlide !== anchors.length - 1) {
pager.animate({
left: '-=' + anchors.eq(nextSlide + 1 - maxvis).outerWidth(true)
}, 'normal');
}
};
} else if (currSlide > nextSlide) { // moving left (negative)
if (anchors.eq(nextSlide - 1).hasClass('resL')) {
anchors.eq(nextSlide - 1).removeClass('resL');
anchors.eq(nextSlide - 1 + maxvis).addClass('resR');
if (nextSlide !== 0) {
pager.animate({
left: '+=' + anchors.eq(nextSlide - 1 + maxvis).outerWidth(true)
}, 'normal');
}
}
}
}
}
});
// Timeouts per slide (in seconds)
var posttimeoutsfeatured = [3650,3650,3650,3650,4,2430,280,450,];
function slideTimeoutfeatured(currElement, nextElement, opts, isForward) {
var index = opts.currSlide;
return posttimeoutsfeatured[index] * 1000;
}

