var baseUrl, order=filter=category=featured_id=episode=''

function verify_comment_form(form) {
    if(form.name.value.length==0) {
        alert("Please enter your name");
        return false;
    }
    if(form.name.value.length<2) {
        alert("Please enter your comment");
        return false;
    }
    return true;
}

function applyPage(p) {
    $("#features_container").html("Loading...");
    $.get(baseUrl, {pge:p,filter:filter,order:order,id:category,featured_id:featured_id,episode:episode}, function(xml) {
        $("#features_container").html(xml);
    });
}

function applyFilter(f) {
    filter = f;
    applyPage(1);
}

function applyEpisode(f) {
    episode = f;
    applyPage(1);
}

function applyOrder(o) {
    order = o;
    applyPage(1);
}

function initStory(s,c,f) {
    baseUrl = s;
    category = c;
    featured_id = f;
    $(document).ready(function() {
       $("#prev").click(function() {

       });
       $("#next").click(function() {

       });
    });
}

function view_asset(type,url) {
    if (type=='slideshow') {
        w=730;h=580;
    }
    else if (type=='graphic') {
        w=524;h=256;
    }
    else if (type=='nominate') {
        w=700;h=580;
    }
    var winl = (screen.width-w)/2;
    var wint = (screen.height-h)/2;
    var position = ',width='+w+',height='+h+',top='+wint+",left="+winl;
    win = window.open(url,null,'menubar=no,location=no,scrollbars=false,resizable=false'+position);
}

function bookmark(whichone) {
    pageUrl = location.href;
	pageTitle = document.title;
	var info = null;
	var output = "";
	switch( whichone ) {
		case "delicious":
			info = getDeliciousInfo(pageUrl,pageTitle);
			break;
		case "digg":
			info = getDiggInfo(pageUrl,pageTitle);
			break;
		case "technorati":
			info = getTechnoratiInfo(pageUrl,pageTitle);
			break;
	}
	if (info !=null) {
	   if (info.onclick=='') {
	       window.open(info.href)
	   }
	   else {
	       window.open(info.href,info.handle,'toolbar=no,width=700,height=400')
	   }
	}
}
function getListItem(info) {
	var output = "<li><a href=\"/social_bookmark/redir/" + info.href + "\" onclick=\"" + info.onclick + "\" class= \"" + info.handle + "\" title=\""+info.alt+"\">" + info.text + "</a></li>";
	return output;
}
function getDeliciousInfo(pageUrl,title) {
	var info = new Object();
	info.handle = "delicious";
	info.text = "del.icio.us";
	info.href = "http://del.icio.us/post?v=4&noui&jump=close&url="+encodeURIComponent(pageUrl)+"&title="+encodeURIComponent(title);
	info.onclick = "window.open(this.href,'"+info.handle+"','toolbar=no,width=700,height=400');return false;";
	info.alt = "del.icio.us";
	return info;
}
function getDiggInfo(pageUrl,title) {
	var info = new Object();
	info.handle = "digg";
	info.text = "Digg";
	info.href = "http://digg.com/submit?phase=2&url="+encodeURIComponent(pageUrl)+"&title="+encodeURIComponent(title)+"&topic=television";
	info.onclick = "";
	info.alt = "Digg!";
	return info;
}
function getTechnoratiInfo(pageUrl,title) {
	var info = new Object();
	info.handle = "technorati";
	info.text = "Technorati";
	info.href = "http://technorati.com/faves/?add="+encodeURIComponent(pageUrl);
	info.onclick = "";
	info.alt = "Technorati";
	return info;
}

function email() {
    pageUrl = location.href;
	pageTitle = document.title;
	url = "/kcet/wiredscience/community/tellfriend?subject="+encodeURIComponent(pageTitle)+"&url="+encodeURIComponent(pageUrl);
	window.open(url,'tell_friend','toolbar=no,width=700,height=480');
}