// JavaScript Document
var $j = jQuery.noConflict();
jQuery(document).ready(function($j){ 

// ROLLOVER
$j(".ro").hover(
 function()
 {
  this.src = this.src.replace(".gif","-ro.gif");
 },
 function()
 {
  this.src = this.src.replace("-ro.gif",".gif");
 });
				
// SLIDESHOW
$j('#slide').cycle({ 
    fx:      'scrollDown', 
    speed:    800, 
    timeout:  5000,
//	easing: 'bounceout'
});

		
// SLIDE THUMBS LEFT AND RIGHT	
/*
$j('#arrow-left').click(function() {
	$j('#peeps-slide1').animate({"left": "+=180px"}, 200);
});
$j('#arrow-right').click(function() {
	$j('#peeps-slide1').animate({"left": "-=180px"}, 200);
});
*/

// SLIDESHOW
/*$j('#peeps-slide').cycle({ 
    fx:      'scrollHorz', 
    speed:    200, 
    timeout:  100000000000,
	next:   '#arrow-right', 
    prev:   '#arrow-left',
	continuous:    0
});*/

// JQUERY TOOLS PEEPS SLIDE
//$j(".scrollable").scrollable({size: 1,clickable:true, loop:false});

// JCAROUSEL
//$j('#peeps-slide').jcarousel({scroll:1});

// HR REPLACE
$j("hr").replaceWith("<div id='hr'><div>");


// MAKE SEARCH FIELD BLANK WHEN CLICK IN
  $j("#ajaxSearch_form input[type=text]").focus(function () {
			$j(this).val("");				 
    });

  $j("#ajaxSearch_form input[type=text]").blur(function () {
			$j(this).val("Search");				 
    });
  
// FLICKR

	// Our very special jQuery JSON fucntion call to Flickr, gets details of the most recent 20 images			   
	$j.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=38571793@N04&lang=en-us&format=json&jsoncallback=?", displayImages);
	
	function displayImages(data) {																																   
		// Randomly choose where to start. A random number between 0 and the number of photos we grabbed (20) minus 9 (we are displaying 9 photos).
		var iStart = Math.floor(Math.random()*(1));
		
		// Reset our counter to 0
		var iCount = 0;								
		
		// Start putting together the HTML string
		var htmlString = "<ul>";					
		
		// Now start cycling through our array of Flickr photo details
		$j.each(data.items, function(i,item){
									
			// Let's only display 9 photos (a 3x3 grid), starting from a random point in the feed					
			if (iCount > iStart && iCount < (iStart + 20)) {
				
				// I only want the ickle square thumbnails
				var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");
				var sourceMed = (item.media.m).replace("_m.jpg",".jpg");
				
				// Here's where we piece together the HTML
				htmlString += '<li><a href="' + sourceMed + '" target="_blank">';
				htmlString += '<img src="' + sourceSquare + '" alt="' + item.title + '" title="' + item.title + '"/>';
				htmlString += '</a></li>';
			}
			// Increase our counter by 1
			iCount++;
		});		
		
	// Pop our HTML in the #images DIV	
	$j('#flickr').html(htmlString + "</ul>");
	
	// Close down the JSON function call
	}

// TRUNCATE BLOG
	//set the desired length of string here
	var strlength1 = 350;
	
	//Go through all tag that match
	$j("span.trim").each(function() {
		//Get length of current string
		var textToTrim = $j(this).html().length;
		//Initialize as string
		var tagText = "";
		
		//If it is greater than the set number...
		if(textToTrim > strlength1){
		
		//Get the current text
		tagText = $j(this).html();
		
		//Trim it to the specified length
		tagText = tagText.substring(0,strlength1);
		
		//Make overwrite current text with the new truncated text
		$j(this).html(tagText);
		
		//Add periods to the end
		$j(this).append('...');
		}
		else{
		//do nothing
		}
	});

// TRUNCATE GIG TITLE
	//set the desired length of string here
	var strlength = 23;
	
	//Go through all tag that match
	$j("#gigs #content h1 a").each(function() {
		//Get length of current string
		var textToTrim = $j(this).html().length;
		//Initialize as string
		var tagText = "";
		
		//If it is greater than the set number...
		if(textToTrim > strlength){
		
		//Get the current text
		tagText = $j(this).html();
		
		//Trim it to the specified length
		tagText = tagText.substring(0,strlength);
		
		//Make overwrite current text with the new truncated text
		$j(this).html(tagText);
		
		//Add periods to the end
		$j(this).append('...');
		}
		else{
		//do nothing
		}
	});

	
});
