/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


jQuery(document).ready(function setList(url_prefix){
	
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('/') + 1).split('/');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('/');
        if(hash != "") {
            vars.push(hash[0]);
        }
        vars[hash[0]] = hash[1];
    }
    return vars;
}


var url_prefix ="";
var url_vars = Array();
    url_vars = getUrlVars();
   
    var url_length = url_vars.length;
   
    if(url_length == 2) {
         url_prefix = "../";
    } 
    else if(url_length == 3) {
         url_prefix = "../../";
    } 
    else if(url_length > 3) {
         url_prefix = "../../../";
    }
    
  if(url_prefix==undefined) {url_prefix="";}
    jQuery.getJSON( url_prefix + "results.json", function(json){ 
             
             var i = 1;
             
             var members = "";
            jQuery.each(json.data, function(i,member){
             members += "<div><a href='" + url_prefix + "tagjaink/" + member.name +"'><img src='" + url_prefix + "wp-content/uploads/" + member.logo +"-150x150.jpg' />" + member.title + "</a></div>";
             });
                     
           jQuery("#slideshow").html(members);
           
            var myList = '#slideshow div';
            var numLow = 0            
            var numHigh = jQuery(myList).length -1;            
            var adjustedHigh = (parseFloat(numHigh) - parseFloat(numLow)) + 1;             
            var numRand = Math.floor(Math.random()*adjustedHigh) + parseFloat(numLow);
           
           jQuery(myList).eq(numRand).attr('class', 'active')
           
  
       });
       

       
});


function slideSwitch() {
    var $active = jQuery('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = jQuery('#slideshow div:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : jQuery('#slideshow div:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 3.0}, 4000, function() {
            $active.removeClass('active last-active');
        });
}

jQuery(function() {
    setInterval( "slideSwitch()", 7000 );
});




