var Video = {
	initialize : function() {
		//Video.play_button();
		//Video.rounded_corners();
	},
	
	play_button : function() {
		var images = $$('.play');
	},
	
	rounder_image_corners : function() {
		jQuery(function($){

		})
	},
	
	rounded_corners : function() {
		jQuery(function($){
			$('.rc').corner('18px');
		})
	}
}

var JuiceBoxJungle = {
	start : function(obj) {
		document.observe("dom:loaded", obj.initialize);
	}
}

JuiceBoxJungle.start(Video);

function goThere(){
var list=document.forms[0].lanuages
location="setlang.asp?lang="+list.options[list.selectedIndex ].value
}


function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

function replace_with_amazon_id(user_amazon_id, text_area_id, code_id)
{
	var code = document.getElementById(code_id).value;
	var new_code = code.replace('juic04-20', user_amazon_id);
    text_area = document.getElementById(text_area_id);
    text_area.value=new_code;
}

function switchAmazon()
{
   setTimeout("Element.hide('amazon1'), Element.show('amazon2')", 5000);
   setTimeout("Element.hide('amazon2'), Element.show('amazon3')", 10000);
   setTimeout("Element.hide('amazon3'), Element.show('amazon1')", 15000);
   setTimeout("Element.hide('amazon1'), Element.show('amazon2')", 240000);

}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function cookieRateUp(cookie_name, story_id){
  var  cookie = ReadCookie(cookie_name);
  var cookie_arr = cookie.split(",");
  if (cookie_arr.indexOf(story_id) >= 0){
    Element.hide('add_'+cookie_name+'_btn_'+story_id);
    Element.show('remove_'+cookie_name+'_btn_'+story_id);
  }
}

function rateUp(vote_type, story_id, count) {
	Element.hide('add_'+vote_type+'_btn_'+story_id);
    Element.show('remove_'+vote_type+'_btn_'+story_id);
    //var elm = document.getElementById(vote_type+'_count-'+story_id);
    //elm.innerHTML = parseInt(count)+1;
}




var Tag = {
	initialize : function()
	{
		var taggables = $$('.taggable');
		var el = $('tag_input');
		
		if (taggables && taggables.length > 0) 
		{
			taggables.each(function(tag)
			{
				tag.observe('click', Tag.toggleTags.bindAsEventListener());
			});	
		}
		
	    if (el)
	    {
	        Tag.highlightTags(el);
			el.observe('keyup', Tag.highlightTagsKey.bindAsEventListener());
	    }
	},
	toggleTags : function(e)
	{
		var target = e.target || e.srcElement;
		var tagName = Tag.parseId(target.id);
		var form = $('post_form');
		var input = form['tag_input'];
		Tag.tagSwap(input, tagName);
		Event.stop(e);
	},
	parseId : function(tag)
	{
		return tag.replace(/^tag_/, '');
	},
	tagSwap : function(el, name)
	{
	    if (!Tag.findTag(el, name))
	    {
	        var normalized = el.value.replace(/^(,?\s*)|(\s*,?)$/g,'');
	        el.value = (normalized == '' ? '' : normalized + ', ') + name;
	        Tag.highlightTags(el);
	    }
	    else
	    {
	        tags = Tag.splitTags(el);
	        newTags = new Array();
	        for (var i = 0; i <= tags.length; i++)
	        {
	            if (tags[i] != name && tags[i] != undefined)
	            {
	                newTags[newTags.length] = tags[i];
	            }
	        }

			newTagsLength = newTags.length;
			joined_tags = '';
			for (var l=0; l < newTagsLength; l++) {
				joined_tags += (l == (newTagsLength-1) ? newTags[l] : newTags[l] + ', ');
			}

			el.value = joined_tags;
	        Tag.highlightTags(el);
	    }
	},
	findTag : function(el, name)
	{
	    var tags = Tag.splitTags(el);
		
	    for (var i = 0; i <= tags.length; i++)
	    {
	        if (tags[i] == name)
	        {
	            return true;   
	        }
	    }
	    return false;
	},
	splitTags : function(el)
	{
		return el.value.split(', ');
	},
	highlightTagsKey : function(e)
	{
		var el = e.target || e.srcElement;
		Tag.highlightTags(el);
	},
	highlightTags : function(el)
	{
	    var tags = Tag.splitTags(el);
	    Tag.clearHighlight();
	
		tags.each(function(tag)
		{
			var tempTag = $('tag_' + tag);
			if (tempTag) 
			{
				tempTag.addClassName('tag_selected');
			}
		});
	},
	clearHighlight : function()
	{
		var highlightedTags = $$('.tag_tag.tag_selected');
		
		highlightedTags.each(function(tag)
		{
			tag.removeClassName('tag_selected');
		});
	}
}

JuiceBoxJungle.start(Tag);

$jQuery(document).ready(function(){

	$jQuery('body').addClass('js');
	
	var tabContainers = $jQuery('div#blogs > div');
			tabContainers.hide().filter(':first').show();
			
			$jQuery('div#blogs ul#blog-nav a').click(function () {
	    		tabContainers.hide();
	    		tabContainers.filter(this.hash).show();
	    		$jQuery('div#blogs ul#blog-nav a').removeClass('active');
	    		$jQuery(this).addClass('active');
	    		return false;
	    	}).filter(':first').click();

	
});

function blog_toggle(link){

  if(!$(link).hasClassName('active')){

    Element.toggle('related-blogs');
    Element.toggleClassName('related','active');
    Element.toggle('popular-blogs'); 
    Element.toggleClassName('popular','active');
  }
}

function changeType(value, id){
	
	var elements = $('content').select('[box="'+id+'"]');

    elements.each(function(elm) {
//	alert('asdf');
	 Element.hide($(elm));
	 });
	
	 Element.show(value+'-'+id);
}

function footage_page(page_num, pages) {
 //hide all the other kids	
  var page = 0;
  while (page<=pages)
  {
   page = page+1;
     if (page == page_num)
     {
	  Element.addClassName('footage_page_link-'+page_num, 'active');
	  Element.show('footage_page-'+page_num);
     }else{
       Element.removeClassName('footage_page_link-'+page_num, 'active');
       Element.hide('footage_page-'+page);
     }
  }


	
}