// JavaScript Document

function alertMe(val){
	//alert(val);	
	//$("#feedback").append("<li>"+val+"</li>");
}

jQuery.fn.paginateList = function(opts) { 

	opts = jQuery.extend({
		itemsPerPage:10,
		btnHolder:".btnHolder",
		startPage:0,
		btnLabel:"page",
		callback:function(){return false;}
	},opts||{});
 		
		var currentPage = opts.startPage;
		
		//opts.startPage = (!opts.startPage || opts.startPage < 0)?1:opts.startPage;
		opts.itemsPerPage = (!opts.itemsPerPage || opts.itemsPerPage < 0)?1:opts.itemsPerPage;
		opts.btnLabel = (!opts.btnLabel)?1:opts.btnLabel;

		var tgt="#"+$(this).attr("id");
		var items = $(this).children(".toPage");
		var totChildren = items.size();
		var totPages = numPages();
		
 		$(tgt).children(".toPage").hide();
 		$(tgt).children(".toPage:lt("+(opts.itemsPerPage)+")").show();
		
		//$("#feedback").append("<li>"+tgt+" "+totChildren+" "+totPages+"</li>");

		var pageButtons = "";
		
		var i;
		
		for(i=0;i<totPages;i++){
			pageButtons +="<a class=\"pageIcon\" href=\"#\" >/ <span>"+(i+1)+"</span> </a>";
		}
		
		if(numPages() > 1){
	
			pageButtons +="<a class=\"changePagePrev\" title=\"p\" href=\"#\" >/ <span>prev</span> </a>";
			pageButtons +="<a class=\"changePageNext\" title=\"n\" href=\"#\" >/ <span>next</span> </a>";
			
			
		}
		
		$(this).children(".articleInfo").children(".btnHolder").html(opts.btnLabel+pageButtons);		
 		$(tgt+" .btnHolder").children("a:eq("+(opts.startPage)+")").addClass("activeBlogFilter");

//alert(tgt);

		$(this).children(".articleInfo").children(".btnHolder").children("a.pageIcon").click(function(){
		 	var gotoPage = $(this).children("span").text()-1;
			var s = (opts.itemsPerPage*gotoPage)-1;
			var e = (s+opts.itemsPerPage)+1;
			showRange(s,e);
			$(this).parent(".btnHolder").children("a").removeClass("activeBlogFilter");
			$(this).addClass("activeBlogFilter");
			currentPage = gotoPage;
		//	alert(s+" "+e);
			return false;
		});
		
		$(this).children(".articleInfo").children(".btnHolder").children("a.changePageNext").click(function(){
				currentPage++;
				if(currentPage==totPages){
					currentPage=0;
				}
				var gotoPage = currentPage;
				var s = (opts.itemsPerPage*gotoPage)-1;
				var e = (s+opts.itemsPerPage)+1;
				showRange(s,e);
				//alert((gotoPage+1));
				$(this).parent(".btnHolder").children("a").removeClass("activeBlogFilter");
				$(this).parent(".btnHolder").children('*:contains("'+(gotoPage+1)+'")').addClass("activeBlogFilter");
				return false;
		});

		
		$(this).children(".articleInfo").children(".btnHolder").children("a.changePagePrev").click(function(){
				currentPage--;
				if(currentPage<0){
					currentPage=totPages-1;
				}
				var gotoPage = currentPage;
				var s = (opts.itemsPerPage*gotoPage)-1;
				var e = (s+opts.itemsPerPage)+1;
				showRange(s,e);
				//alert((gotoPage+1));
				$(this).parent(".btnHolder").children("a").removeClass("activeBlogFilter");
				$(this).parent(".btnHolder").children('*:contains("'+(gotoPage+1)+'")').addClass("activeBlogFilter");
				return false;
		});
		
		function numPages() {
			return Math.ceil(totChildren/opts.itemsPerPage);
		}
		
		function showRange(a,b) {
			$(tgt).children(".toPage").hide();
		//	$(tgt).children(".toPage:lt("+b+")").filter(":gt("+a+")").show();
			$(tgt).children(".toPage:lt("+b+")").filter(":gt("+a+")").fadeIn(200);
		}
		
		
	 
};


jQuery.fn.filterList = function() { 
		
		var tgt="#"+$(this).attr("id");
		var filterItem = $(this).children(".toFilter");
		var totChildren = filterItem.size();
		var filterTypesArray=[];
		var pageButtons="";
		var btnLabl = "page";
 		
		$(this).children(".toFilter").each(function(){
			var toFilterType = $(this).attr("label")
			var inA =$.inArray(toFilterType, filterTypesArray)
			if(inA<0){
			//	alert(toFilterType);
 				if(toFilterType){
					filterTypesArray.push(toFilterType);
					pageButtons +=" / <a href=\"#\">"+toFilterType+"</a>";
				}
			}
		});

		pageButtons +=" / <a href=\"#\" class=\"activeBlogFilter\">all</a>";

		$(this).children(".articleInfo").children(".btnHolder").html(pageButtons);
		
		$(this).children(".articleInfo").children(".btnHolder").children("a").click(function(){
			var showType=$(this).text();
		//	alert(showType);
		//	$(".toFilter").hide();
			
			$(this).parent(".btnHolder").children("a").removeClass("activeBlogFilter");
			$(this).addClass("activeBlogFilter");
			
			if(showType=="all"){
				$(tgt).children(".toFilter").fadeIn(200);
			}else{
				$(tgt).children(".toFilter").hide();
				$(tgt).children(".toFilter[label="+showType+"]").fadeIn(200);
			}
			return false;
		//	$(this).parent(".toFilter[label="+$(this).text()+"]").show();
		});
		
};


jQuery.fn.makeDirectorLink=function(b,alt){function a(e,j){var l=0;if(e.nodeType==3){var k=e.data.toUpperCase().indexOf(j);if(k>=0){
	var h=document.createElement("a");
	h.className="directorTextLink";
	h.href=alt;
	var f=e.splitText(k);
	var c=f.splitText(j.length);
	var d=f.cloneNode(true);
	h.appendChild(d);
	f.parentNode.replaceChild(h,f);l=1}}else{if(e.nodeType==1&&e.childNodes&&!/(script|style)/i.test(e.tagName)){for(var g=0;g<e.childNodes.length;++g){g+=a(e.childNodes[g],j)}}}return l}return this.each(function(){a(this,b.toUpperCase())})};jQuery.fn.removeHighlight=function(){return this.find("span.highlight").each(function(){this.parentNode.firstChild.nodeName;with(this.parentNode){replaceChild(this.firstChild,this);normalize()}}).end()
	};
	
jQuery.fn.changeMatchedStyle=function(b,alt,newEl){function a(e,j){var l=0;if(e.nodeType==3){var k=e.data.toUpperCase().indexOf(j);if(k>=0){
	var h=document.createElement(""+newEl+"");
	h.className=alt;
	h.href="/director/"+alt;
	var f=e.splitText(k);
	var c=f.splitText(j.length);
	var d=f.cloneNode(true);
	h.appendChild(d);
	f.parentNode.replaceChild(h,f);l=1}}else{if(e.nodeType==1&&e.childNodes&&!/(script|style)/i.test(e.tagName)){for(var g=0;g<e.childNodes.length;++g){g+=a(e.childNodes[g],j)}}}return l}return this.each(function(){a(this,b.toUpperCase())})};jQuery.fn.removeHighlight=function(){return this.find("span.highlight").each(function(){this.parentNode.firstChild.nodeName;with(this.parentNode){replaceChild(this.firstChild,this);normalize()}}).end()
};
	
jQuery.fn.fadeToggle = function(speed, easing, callback) { 
   return this.animate({opacity: 'toggle'}, speed, easing, callback); 
};

function resizeItem(){
	
	//alert("1");
	//$("#"+tgt).css("height",h);
	
  
}
 
function setPlayingStyle(tgt, section, newH){
	
	//alert("'"+tgt+"' '"+section+"'")
	
	$("div.directorIndexDiv").removeClass("playingThisVideo");
	$("#"+tgt).addClass("playingThisVideo");
	
	if(newH){
		
		newH += "px";
		document.getElementById("flashVideoHolder").style.height = newH;
		
	}
 //	return false;
 
}

 
function processColour(val){
	var valConverted;
	
	//requires jquery.colour.js
	
	/*if($.isHexadecimalColor(val)){
		valConverted = $.fmtColor(val,'hexadecimal');		
		//alert("isHexadecimalColor "+val+" "+valConverted);
		return valConverted;
	}else if($.isRGBColor(val)){
		valConverted = $.fmtColor(val,'hexadecimal');
		//alert("isRGBColor "+val+" "+valConverted);
		return valConverted
	}else if($.isColor(val)){
		valConverted = $.fmtColor(val,'hexadecimal');
		//alert("isColor "+val+" "+valConverted);
		return valConverted;
	}*/
	 
}


