$ = jQuery.noConflict();// heheh

	// load playlist video
    	function showlistall(data) {    
			var width = 100;
			var height = 340/560 * width;
        	var feed = data.feed;
        	var entries = feed.entry || [];
        	var html = [];
			var perpage = 9;// - 1
			var x = 1;
			var y = 1;
			
			html.push('<div class="playlistpage">');
			
          for (var i = 0; i < entries.length; i++) {        	
        		var width = "<?php echo $width; ?>";
        		var height = "<?php echo $height; ?>";
        		var showtitle = "<?php echo $showtitle; ?>";
        		var titledisplay = '';        		
        		

        		// Parse out YouTube entry data				
				var entry = entries[i];
				
				if(i == 0){                								
          if(currentVideoId) {
            currentVideoId = currentVideoId;
          } else {
            currentVideoId = entry.media$group.yt$videoid.$t;
          }          			
        }
				
			if (entry.media$group.media$thumbnail) {
				var title = entry.title.$t;
				var tlength = secondsToString(entry.media$group.media$content[0].duration);//entry.yt$duration.seconds.valueOf();	
				
				var playerUrl = entry.media$group.media$content[0].url;
				var thumbnailUrl = entry.media$group.media$thumbnail[0].url;		
				//move to load var playCount = '0';//entry.yt$statistics.viewCount;//entry.yt$statistics.viewCount.valueOf();
				//move to load var vdescription = entry.media$group.media$description.$t;				
				var likes = '0::0';
				if (entry.yt$rating){
					//var likes = entry.yt$rating.numLikes.valueOf()+'::'+entry.yt$rating.numDislikes.valueOf();			
					var likes = entry.yt$rating.numLikes+'::'+entry.yt$rating.numDislikes;			
				} 
				// form old codes... hymmm tired
				var videoid = entry.media$group.yt$videoid.$t;//playerUrl.replace('http://www.youtube.com/v/', ''); // added by fritz 11-25-2010
				//videoid = videoid.replace('?f=playlists&app=youtube_gdata', '');  // added by fritz 11-25-2010       				
        		titledisplay = '<span class="media-title">'+ title + '</span>';
      
			 var thumb = '<span class="media-thumb"><span class="m-thumbs"><img class="videothumb" id="'+videoid+'::'+likes+'" src="'+thumbnailUrl+'" style="max-width:'+width+';" /></span><span class="media-length semibg">'+tlength+'</span></span>';			             
			html.push('<div class="media-list">'+thumb+''+titledisplay+'</div>' );
			x++;

				if (i==0) { // check first video load
					var lvideo_param = videoid+'::'+likes;
					brk = '';
				} else if((i+1) == entries.length) {
					html.push('</div>');
					y++;
					x = 1;
				} else if (x == perpage){
					html.push('</div><div class="playlistpage">');
					y++;
          x = 1;
				} else {
					brk = '';  
				} 	
				// based on session
				if (currentVideoId == videoid) { // check likes dislikes				  
					var lvideo_param = videoid+'::'+likes;					 											
				}				
		  }
		}//for        	   		 		  
          $('#channellist-all').html(html.join(''));
          if (y>1) {
             $('.pagenextprev').fadeIn();
          }
          $('#videonavigationcircle').empty();
          $("#channellist-all").cycle({
          fx: "scrollHorz",  cleartypeNoBg: true, 
          pause:1,    
          before: function(curr, next, opts) {
          opts.animOut.opacity = 0;
          },
		  after: function (curr,next,opts) {				
			  
			  //get the height of the current slide
			  var $ht = $(this).height();
			  //set the container's height to that of the current slide
			  $(this).parent().css("height", $ht);
			},
          containerResize: 0, 
          randomizeEffects:0,
          fastOnEvent:0, fit:1,
          speed: 1000,timeout: 0,
          next: "#v-next", prev: "#v-prev", pager: "#videonavigationcircle"}); // end slides  

          
		  $('#playlistpagination').fadeIn();
		  
      // load first video
      loadvideo(lvideo_param, 0);	

		// video click
		  $('.videothumb').click(function (){
		    initialvideo(this);
		   });
		// image prealoader   
		  $.preload( '.videothumb', {
				placeholder:rooturltemp+ '/images/ajax-loader.gif',
				notFound:rooturltemp+ '/images/media-no-thumb.png'
			});
  	/*
    function onAfter(curr, next, opts) {
  	  $('#slideShowContainer').css('overflow', 'visible');
  	  $h = $('#slideShowContainer .news-cycle:eq('+opts.currSlide+')').find('.news-main').height();
  	  if($h > 413){
  	  	$('#content').css('height',$h);
  	  }
  	  else{
  	  	$('#content').css('height','413');
  	  }
  	  showShareButtons(opts.currSlide);
  	  navigationshows(opts);
  	  
  	}
  	function navigationshows(opts){
  	  // hide navigation if first/last added by fritz 07-28-2011	  
  			if ((opts.currSlide +1) == 1) {					
  				// hide the prev
  				$('#news-left').hide();
  				$('#news-right').show();
  			} else if ((opts.currSlide +1) == opts.slideCount) {
  				// hide the next
  				$('#news-left').show();
  				$('#news-right').hide();				
  			} else {
  				$('#news-left').show();
  				$('#news-right').show();						
  			}  
    } */         	      
	  }//showlistall
  //bit_url function
  function bit_url(pagelink) { 
    var url=pagelink['url'];
    var username="f5digitaloperations"; // bit.ly username
    var key="R_2a8e89398e5e7463c63e76a84a1dbc1e";
    $.ajax({
    url:"http://api.bit.ly/v3/shorten",
    data:{longUrl:url,apiKey:key,login:username},
    dataType:"jsonp",
    success:function(v)
      {
      var shorten_url=v.data.url; 
      $('#media-btn-sharethis').show();                                           
			$('#media-btn-sharethis').html('<span class="st_sharethis_button" displayText="ShareThis" st_url="'+shorten_url+'" st_title = "'+pagelink['title']+'" st_image = "'+pagelink['image']+'" st_summary="'+pagelink['excerpt']+'" ></span>');
			if (stButtons){stButtons.locateElements();} // Parse ShareThis markup
      //return bit_url_now;
      }
    });            
  } //bit_url       	
	function updateShareThis(pagelink){  
    // make it possible.. grrr
      var shorten_url = encodeURI(pagelink['url']); 
      $('#media-btn-sharethis').show();                                           
			$('#media-btn-sharethis').html('<span class="st_sharethis_button" displayText="ShareThis" st_url="'+shorten_url+'" st_title = "'+pagelink['title']+'" st_image = "'+pagelink['image']+'" st_summary="'+pagelink['excerpt']+'" ></span>');
			if (stButtons){stButtons.locateElements();} // Parse ShareThis markup     
    //bit_url(pagelink);                                                      
  }  	
	// convert seceonds with minutes
	function secondsToString(seconds) {
	
		var numdays = Math.floor(seconds / 86400);
		var numhours = Math.floor((seconds % 86400) / 3600);
		var numminutes = Math.floor(((seconds % 86400) % 3600) / 60);
		var numseconds = ((seconds % 86400) % 3600) % 60;
		numseconds = String(numseconds);
		if (numseconds.length == 1) {
			numseconds = '0'+numseconds;
		}
		if (numhours >0){
			return numhours + ":" + numminutes + ":" + numseconds;
		} else {		
			return numminutes + ":" + numseconds;
		}		
	} // end secondsToString()	  
	
	// relative time from f5de.. not so much good
	function relative_time(published){
		var friendlyDate = '';
		var postDate = new Date();
		
		postDate.setUTCFullYear(published.substring(0, 4));
		postDate.setUTCMonth(parseInt(published.substring(5, 7)) - 1);
		postDate.setUTCDate(published.substring(8, 10));
		postDate.setUTCHours(published.substring(11, 13));
		postDate.setUTCMinutes(published.substring(14, 16));
		postDate.setUTCSeconds(published.substring(17, 19));
		
		var dateDiff = Math.round(((new Date()).getTime() - postDate.getTime()) / 1000);
		
		if (dateDiff < 3600) {
			dateDiff = Math.floor(dateDiff / 60);
			friendlyDate = dateDiff + ' minute' + (dateDiff > 1 ? 's' : '') + ' ago';
		}
		else if (dateDiff < 86400) {
			dateDiff = Math.floor(dateDiff / 3600);
			friendlyDate = dateDiff + ' hour' + (dateDiff > 1 ? 's' : '') + ' ago';
		}
		else if (dateDiff < 604800) {
			dateDiff = Math.floor(dateDiff / 86400);
			friendlyDate = dateDiff + ' day' + (dateDiff > 1 ? 's' : '') + ' ago';
		}
		else {
			dateDiff = Math.floor(dateDiff / 604800);
			friendlyDate = dateDiff + ' week' + (dateDiff > 1 ? 's' : '') + ' ago';
		}	
		return friendlyDate;
	} // END relative_time()
	
	//add commas http://www.mredkj.com/javascript/numberFormat.html
	function addCommas(nStr){
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	} // END addCommas
  // textarea count
  var maxAmount = 500;
  function textCounter(textField, showCountField) {
      if (textField.value.length > maxAmount) {
          textField.value = textField.value.substring(0, maxAmount);
	  } else { 
			  showCountField.value = maxAmount - textField.value.length;
	  }
  } // END textCounter	
/** END VIDEO ************************************************************/  

/* START CONCEPT ************************************************************/
    function previewConcept(str){      
  		var ids = str.replace("-150x150", "");    		
  		$('.concept-large-thumb img').attr('src', str);    
    }
	function initialJquery_concept() {
	  $("#conceptpages").cycle({
	  fx: "scrollHorz",  cleartypeNoBg: true, 
	  pause:1,    
	  before: function(curr, next, opts) {
	  opts.animOut.opacity = 0;
	  },
	  containerResize: 0, 
	  randomizeEffects:0,
	  fastOnEvent:0, fit:1,
	  speed: 1000,timeout: 0,
	  next: "#c-next", prev: "#c-prev", pager: "#conceptnavigationcircle"}); // end slides  		
    //hover START
	  $.preload( '.concept-thumb img', {
			placeholder:rooturltemp+ '/images/loading.gif',
			notFound:rooturltemp+ '/images/media-no-thumb.png'
	  });  	
    $('a.concept-thumbright img').hover(function(){
      var str = $(this).attr('src');
      previewConcept(str);	        	
    });	
    $('a.concept-thumbright').hover(function(){
      $('a.concept-thumbright').removeClass('creamborder').addClass('greyborder');    
      $(this).removeClass('greyborder').addClass('creamborder');        
    });
    //hover END
    $('a.concept-thumb').click(function(){
      var ids = $(this).attr('id')+'-details';
      var str = $('#'+$(this).attr('id')+' img').attr('src');
      var c = $(this).attr('id');      
      $('#thumblist_bottom .entry').slideDown(function (){
        $('.b-'+c).hide();
      }); 
               
      previewConcept(str);	            	    		
  		//$('#thumbslist').slideUp('slow',function(){
      $('#thumbslist').animate({marginRight: -500,opacity: 0},500,function(){
        $('#thumbslist').hide('fast');				
        //$('#concept-details').slideDown('slow', function(){
        $('#concept-details').show();
        $('#concept-details').animate({marginLeft: 0,opacity: 1},500, function(){          
          //$(this).fadeIn();
  				$('#concept-details-content').html($('#'+ids).html());     
          //Cufon.replace('#concept-details-content h2.sub-posttitle');
          //$('#c-thumblist_bottom').show('slide', {direction: 'up'} );
          $('#c-thumblist_bottom').show('fast');           
          $('#c-sharing_bottom').fadeOut('slow', function(){$('#c-thumblist_bottom').animate({marginLeft: 0,opacity: 1},500);$('#c-sharing_bottom').animate({marginLeft: -960,opacity: 0},500);});          
  		  });            
      });  		  		
	    return false;
    });	
    
    // back            
	  $('#concept-details-back').click(function (){
			//$('#concept-details').slideUp('slow', function(){			
      $('#concept-details').animate({marginLeft: -500,opacity: 0},500, function(){
        $('#concept-details').hide('fast');      
        $('#thumbslist').show('fast');
        $('#c-sharing_bottom').fadeIn();
        $('#thumbslist').animate({marginRight: 0,opacity: 1},500);      			
        $('#c-thumblist_bottom').animate({marginLeft: -960,opacity: 0},500,function(){$('#c-sharing_bottom').animate({marginLeft: 0,opacity: 1},500);});
  			$('#c-thumblist_bottom').hide('fast');
  			//$('#thumbslist').slideDown('slow');																
			});									 
	   });
	} //initialJquery_concept()
/** END CONCEPT ************************************************************/
	  
/** START live feeds RSS ************************************************************/  
	
	
  function scrollPf() {
	
	if ($("#page-feed").css("top").substring(0, $("#page-feed").css("top").length - 2) <= ($("#page-feed").height() * -1 )) {
	
	  $("#page-feed").css("top", "0px");	
	
	}
	
	$("#page-feed").animate({ "top" : ($("#page-feed").css("top").substring(0, $("#page-feed").css("top").length - 2) - 4) + "px" }, 99);
	
	}	
	
	
	
	function getLatestRssNews() {
	
	$.ajax({
	
	  url: rooturltemp+"/php/get-latest-rss-news.php",
	
	  success: function(response) {
	
		   $('#latest-news ul').html(response);
	
	   }
	
	});        
	
	}
	function getLatestRssFeeds(container) {
	    
      $.ajax({ url: rooturltemp+"/php/live.php", success: function(response) {
      $("#page-feed").html(response);
	  //var intervalPf = setInterval('scrollPf()', 150);
	  
	   $jScroller.add("#page-feed-scroller","#page-feed","up",1,true);
	   $jScroller.start();
    
    }});     
	
	}	
/** END live feeds RSS ************************************************************/  	  

    function workWithUs(){     
        var sliderOptions1 = {      
            effect: "boxRain", 
            boxCols: 15,
            boxRows: 12,
            slices: 20, 
            animSpeed: 300,
            pauseTime: 6910,
            startSlide: 0,
            directionNav: false,
            directionNavHide: false,
            controlNav: false,
            controlNavThumbs: false,
            keyboardNav: false,
            pauseOnHover: false,
            manualAdvance: false
        };

        var sliderOptions2 = {
            effect: "boxRandom", 
            boxCols: 8,
            boxRows: 12,
            slices: 15, 
            animSpeed: 300,
            pauseTime: 5450,
            startSlide: 0,
            directionNav: false,
            directionNavHide: false,
            controlNav: false,
            controlNavThumbs: false,
            keyboardNav: false,
            pauseOnHover: false,
            manualAdvance: false
        };

        var sliderOptions3 = {
            effect: "boxRainGrowReverse", 
            boxCols: 8,
            boxRows: 8, 
            slices: 12,
            animSpeed: 300,
            pauseTime: 4780,
            startSlide: 0,
            directionNav: false,
            directionNavHide: false,
            controlNav: false,
            controlNavThumbs: false,
            keyboardNav: false,
            pauseOnHover: false,
            manualAdvance: false
        };

        var sliderOptions4 = {
            effect: "boxRainGrow", 
            boxCols: 8,
            boxRows: 8,
            slices: 12, 
            animSpeed: 300,
            pauseTime: 6230,
            startSlide: 0,
            directionNav: false,
            directionNavHide: false,
            controlNav: false,
            controlNavThumbs: false,
            keyboardNav: false,
            pauseOnHover: false,
            manualAdvance: false
        };
  		  // image preloader
		  /*$.preload( '.workgallery', {
  				placeholder:rooturltemp+ '/images/loading.gif',
  				notFound:rooturltemp+ '/images/media-no-thumb.png'
  		  });*/  
		  
          $("#work-whygalleryleft").nivoSlider(sliderOptions1);
          $("#work-whygallerycenter").nivoSlider(sliderOptions2);
          $("#work-whygalleryrighttop").nivoSlider(sliderOptions3);
          $("#work-whygalleryrightbot").nivoSlider(sliderOptions4);
    }
  // event/ news slides	
  function contentVerticalScroll(){
		var perslide = 3;								   
  		$(".vertical").cycle({
  			fx:"scrollVert",  cleartypeNoBg: true,
			/*easing: 'easeInOutExpo',
  			before: function(curr, next, opts) {
  				opts.animOut.opacity = 0;
  			},*/
            after: function (curr,next,opts) {
				if ((opts.currSlide +1) == 1) {
					// hide the prev
					$('#actions-up').css({'opacity':0});
					$('#actions-down').css({'opacity':1});
				} else if ((opts.currSlide +1) == opts.slideCount) {
					// hide the next
					$('#actions-up').css({'opacity':1});
					$('#actions-down').css({'opacity':0});				
				} else {
					$('#actions-up').css({'opacity':1});
					$('#actions-down').css({'opacity':1});						}
	            //var msg = (opts.currSlide +1) +' -- ' + opts.slideCount;     
				//alert(msg);
            }, 			
  			speed: 2000,timeout: 0, slideResize:0,
  			next: "#actions-down", prev: "#actions-up"
  		}); // end slides   	
  }
  // dump array
	function dump(arr,level) {
		var dumped_text = "";
		if(!level) level = 0;
		
		//The padding given at the beginning of the line.
		var level_padding = "";
		for(var j=0;j<level+1;j++) level_padding += "    ";
		
		if(typeof(arr) == 'object') { //Array/Hashes/Objects 
			for(var item in arr) {
				var value = arr[item];
				
				if(typeof(value) == 'object') { //If it is an array,
					dumped_text += level_padding + "'" + item + "' ...\n";
					dumped_text += dump(value,level+1);
				} else {
					dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
				}
			}
		} else { //Stings/Chars/Numbers etc.
			dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
		}
		return dumped_text;
	}

