// JavaScript Document
var $j = jQuery.noConflict() ;
$j(document).ready(function() {
    if($j("#featured").length > 0){
        //slideshow() ;
        featured() ;
    }

}); 
// Home Slideshow
var item = 0 ;
var items ;
var itemWidth ;
var itemHeight;
var slideshowUl ;
var controls ;
var nextPos ;
var nextLimit ;
function slideshow() {
    items = $j("#featured li") ;
    itemWidth = $j("#featured li:first").width() ;
    itemHeight = $j("#featured li:first").height() ;
    slideshowUl = $j("#featured ul") ;
    controls = $j("#featured .controls") ;
    
    $j("#featured").width(itemWidth) ;
    $j(slideshowUl).width(itemWidth * items.length) ;
    $j(slideshowUl).css("overflow", "hidden") ;
    items.css("float", "left") ;
    controls.css("margin-top", "-" + (itemHeight/2)-20 + "px").width(itemWidth) ;
    nextPos = itemWidth - 40 ;
    $j(".next").css("left", nextPos + "px") ;
    nextLimit = (slideshowUl.width() - itemWidth) * -1 ;
    
    $j(".next").click(function() {
        slideshowNext(this) ;
    });
    $j(".prev").click(function() {
        slideshowPrev(this) ;
    });

    autoPlay = setInterval("cycleSlide()", 15000) ;
}
function slideshowNext(e) {
    if(item < items.length -1 ) {
        item++ ;
        slideshowPage(item) ;
    }
}
function slideshowPrev(e) {
    if(item > 0 ) {
        item-- ;
        slideshowPage(item) ;
    }
}
function slideshowPage(item) {
    slideshowUl.stop().animate({
        left: "-" + itemWidth * item
    },500);
}
function cycleSlide() {
    if(item == items.length) {
        item = 0 ;
    }
    slideshowPage(item) ;
    item++ ;
}
function isHtml5() {
    var z = document.createElement('canvas') ;
    return !!(z.getContext && z.getContext('2d'));
}
function featured() {
    var player = '' ;
    if(!isHtml5()) {
        player = '<object height="370" width="100%"> <param name="movie" value="https://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F1509015&amp;show_comments=false&amp;auto_play=false&amp;show_playcount=true&amp;show_artwork=true&amp;color=ff7700"></param> <param name="allowscriptaccess" value="always"></param> <embed allowscriptaccess="always" height="370" src="https://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F1509015&amp;show_comments=false&amp;auto_play=false&amp;show_playcount=true&amp;show_artwork=true&amp;color=ff7700" type="application/x-shockwave-flash" width="100%"></embed> </object>' ;
    } else {
        player = '<iframe width="100%" height="370" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F1509015&amp;auto_play=false&amp;show_artwork=true&amp;color=ff7700"></iframe>' ;
    }
    $j('#featured').html(player) ;
}
