(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevIdInactive:	'prevBtn1',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextIdInactive:	'nextBtn1',
			nextText: 		'Next',
			pauseId: 		'pauseBtn',	
			pauseText: 		'Pause',
			playId: 		'playBtn',
			playText: 		'Play',
			play1Id: 		'play1Btn',
			play1Text: 		'Play',			
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			600,
			auto:			false,
			pause:			5000,
			continuous:		false
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			//obj.width(w); 
			//obj.height(h); 
			var h = 550; 
			obj.css("overflow","hidden");
			var ts = s-1;
			
			if(ts == 0)
			{
				$("a","#"+options.pauseId).hide();
				$("a","#"+options.playId).hide();	
			}
			
			$("a","#"+options.prevId).hide();
			$("img","#"+options.prevIdInactive).show();	
			
			var t = 0;
			$("ul", obj).css('width',s*w);			
			if(!options.vertical) $("li", obj).css('float','left');
			html += ' <span id="'+ options.playId +'"><a href=\"javascript:void(0);\">'+ options.playText +'</a></span>';
				html += ' <span id="'+ options.pauseId +'"><a href=\"javascript:void(0);\">'+ options.pauseText +'</a></span>';
			if(options.controlsShow){
				var html = options.controlsBefore;
				
				
						
				if(options.firstShow) html += '<span  id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
				
			
				html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\"><img alt="" src="templates/ETF_Digest/images/lft-arrow.gif"/>'+ options.prevText +'</a></span>';
								
				html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
				
				
				
				if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';
				html += options.controlsAfter;						
				//$(obj).after(html);			
				
			};
	
			$("a","#"+options.nextId).click(function(){	
													 
						
				//var t = $(this).attr('href');	
				
				var url = $.jqURL.url();
				
				
				var _s = url; // haystack
				var _m = '#'; // needle
				var _c = 0;
				for (var i=0;i<_s.length;i++) {
				if (_m == _s.substr(i,_m.length))
				_c++;
				}
				

				if(_c == 0)
				{
					var t = 1;	
				}
				else
				{
					var ran_url = url.split('#'); 
					if(ran_url[1] == 'comment') 
						ran_url[1] = 0 ;
					var t = parseInt(ran_url[1]) + 1;				
				}
			
				
				//alert(t);
				var tab = "#cat_" + chartArray[t];
		      //var hid = $("#test").val();
				playgroup(t,tab,true,1);
			
				//$("a","#"+options.pauseId).hide();
				//$("a","#"+options.playId).show();
				//$("a","#"+options.play1Id).hide();
			});
			
			
			$("a","#comment_show").click(function(){	
				var t= 0;							 
				//alert("hai");
				
				$(".Chartpara-txt1 > *").removeClass('active');				
				//$(tab).addClass('active');	
				
				$(".Chartpara-txt1 a:first-child").addClass('active');
				
				$("#slider ul").css({
					"margin-left" : "0px"
					});
				  
				$("a","#"+options.prevId).hide();
				$("img","#"+options.prevIdInactive).show();	
				  
				 //$('#nextBtn a').attr('href','#0');

				
			});
			
		
			
				$("a","#"+options.prevId).click(function(){	
			
				//var t = $(this).attr('href');	
				
				var url = $.jqURL.url();
				var ran_url = url.split('#'); 
				if(ran_url[1] == 'comment') 
						ran_url[1] = 0 ;
				var t = parseInt(ran_url[1]) - 1;	
				
				var tab = "#cat_" + chartArray[t];
		      
				playgroup(t,tab,true,2);
			
				//$("a","#"+options.pauseId).hide();
				//$("a","#"+options.playId).show();
				//$("a","#"+options.play1Id).hide();
			});
			
			
			function playgroup(t,tab,paused,ccc){			
			//pauses("pause",true,'1');	
			
			
			var hid = $("#test").val();
			//alert(t);
//			if(ccc==1){
//				    inc = parseInt(hid)+1; alert(inc);
//				  t = inc;
//				  document.getElementById('test').value = parseInt(inc);
//				}
//				if(ccc==2){
//					var  dec = parseInt(hid)-1;
//				     t = dec;
//					 document.getElementById('test').value = dec;
//					}
//			
			
		
			$("a","#"+options.prevId).show();
			$("img","#"+options.prevIdInactive).hide();	
			
			$("a","#"+options.nextId).show();
			$("img","#"+options.nextIdInactive).hide();	
		
		
		//	if(tab == 1)
//			{
//			tab = '#cat_' + $('#slider li').eq(t).attr('value');
//			
//			var tr = parseInt(t);
//			var ty = parseInt(t);
//			
//			if(ccc == 1)
//			var tr = parseInt(t) + 1;	
//			
//			if(ccc == 2)
//			var ty = parseInt(t) - 1;
//			
//			}
//			else
//			{
//			var tr = parseInt(t);		
//			var ty = parseInt(t);	
//			}
			
			
			
			var tr = parseInt(t);				
			var ty = parseInt(t);
			
	    var nx = parseInt(t);
		var px = parseInt(t);
	
	//		var tr = parseInt(t);				
	//		var ty = parseInt(t);
			
			
			if(tr == (s-2))
			{
				$("a","#"+options.nextId).hide();
				$("img","#"+options.nextIdInactive).show();	
			}
			
			if(ty == 0)
			{
				$("a","#"+options.prevId).hide();
				$("img","#"+options.prevIdInactive).show();	
			}
			
				
			tr = '#' + tr.toString();
			ty = '#' + ty.toString();

			
					
						
			
			$(".Chartpara-txt1 > *").removeClass('active');				
			$(tab).addClass('active');			
			$("#slider ul").css({
			"margin-left" : ((-t) * 490) + "px"
			});		
			
//			document.getElementById('ntest').value = nx;
//			document.getElementById('ptest').value = px;
/*			alert(tr);
			 tr = tr.substr(1);
			 tr = parseInt(tr)-1;
			 tr = '#' + tr.toString();alert(tr);
*/			
			$('#prevBtn a').attr('href',ty);		
			$('#nextBtn a').attr('href',tr);	
			
			}		
			
			
				$("a",".Chartpara-txt1").click(function(){		
													
				$("a","#"+options.pauseId).hide();
				$("a","#"+options.playId).hide();										
				t = $(this).attr('href');	
				var tab = '#' + $(this).attr('id');				
				playgroup(t.substr(1),tab,true);
			
			
				
			});	
				
			
			//$("a","#"+options.prevId).click(function(){		
			//	animate("prev",true);
			//	$("a","#"+options.pauseId).hide();
			//	$("a","#"+options.playId).show();
			//	$("a","#"+options.play1Id).hide();
			//});	
			$("a","#"+options.firstId).click(function(){		
				animate("first",true);
			});				
			$("a","#"+options.lastId).click(function(){		
				animate("last",true);				
			});		
			
			$("a","#"+options.pauseId).click(function(){		
				pauses("pause",true);				
			});	
			$("a","#"+options.playId).click(function(){		
				plays("next",true);	
				
			});
			
			$("a","#"+options.play1Id).click(function(){
				$("a","#"+options.play1Id).hide();	
				$("a","#"+options.playId).hide();
				var url = $.jqURL.url();
				var ran_url = url.split('#'); 
				plays("next",true,ran_url[1]);					
			});	


			
				
		
		
		
			if(!options.continuous && options.controlsFade){
				$("a","#"+options.nextId).show();
				//$("a","#"+options.prevId).show();
				//$("img","#"+options.prevIdInactive).show();
				if(ts==0){
				$("a","#"+options.nextId).hide();
				$("img","#"+options.nextIdInactive).show();
				$("img","#"+options.nextIdInactive).show();
				}
				else
				{
				$("a","#"+options.nextId).show();
				$("img","#"+options.nextIdInactive).hide();
				$("a","#"+options.playId).hide();
				$("a","#"+options.play1Id).hide();
				}
				//$("a","#"+options.firstId).hide();				
			};				
			
		});
	  
	};

})(jQuery);




/*
jqURL
by Josh Nathanson

various manipulations on url strings and windows.  
all functions can also take a window object as an argument,
for example {win:opener}
but will default to current window if none is passed.

public functions:

-------------------------
.url({ 
	 win:window object 
	 })
-------------------------
returns the whole url string
like win.location.href

	so if the current window href is "http://www.mysite.com?var1=1&var2=2&var3=3"
	
	$.jqURL.url() returns "http://www.mysite.com?var1=1&var2=2&var3=3"
	
	
------------------------------
.loc(urlstr:string, 
	 { 
	 win:window object, 
	 w:integer, 
	 h:integer, 
	 t:integer,
	 l:integer,
	 wintype:string('_top'[default],'_blank','_parent') )
	})
------------------------------																			 
- directs passed in window to urlstr, which is required
- works like window.location.href = 'myurl'
- but you can also use it to pop open a new window by passing in "_blank" as the wintype
- if popping open a window, defaults to center of screen

	so
	$.jqURL.loc('http://www.google.com',
				{w:200,h:200,wintype:'_blank'});
	would open Google in a new centered 200x200 window
	
	or, locate an url to any named window:
	$.jqURL.loc('http://www.google.com',{ win:mywindow });
	opens Google in mywindow


------------------------------
.qs({ 
	ret:string('string'[default],'object'), 
	win:window object })
------------------------------
returns querystring, either string (pass ret:'string' [default])
or object (pass ret:'object') 

	so if the current window href is "http://www.mysite.com?var1=1&var2=2&var3=3"

	$.jqURL.qs();
	returns "var1=1&var2=2&var3=3"
	
	$.jqURL.qs({ ret:'object' });
	returns Object var1=1,var2=2,var3=3


------------------------------
.strip({ keys:string(list of keys to strip), win:window object })
------------------------------
if passed with no arguments, returns url with '?' and query string removed
if you pass in list of keys, it returns url with the specified key-value pairs removed

	so if the current window href is "http://www.mysite.com?var1=1&var2=2&var3=3"

	$.jqURL.strip();
	will return
	"http://www.mysite.com"
	
	$.jqURL.strip({ keys:'var1,var2' });
	will return
	"http://www.mysite.com?var3=3"
	
	
-------------------------------------
.get(key, {win:window object})
-------------------------------------
returns value of passed in querystring key

	so if the current window href is "http://www.mysite.com?var1=1&var2=2&var3=3"
	$.jqURL.get('var2');
	will return 2

--------------------------------------
.set(hash, {win:window object})
--------------------------------------
returns the window's url, but with the keys/values set in the query string
if the keys already exist, re-sets the value
if they don't exist, they're appended onto the query string

*/

jQuery.jqURL = {

	url : // returns a string
	function(args) {
		args = 
			jQuery.extend({
				win : window
			},
			args);
		return args.win.location.href;
	},
	
	loc : 
	function(urlstr, args) {
		args = 
			jQuery.extend({
				win : window,
				w : 500,
				h : 500,
				wintype : '_top'
			},
			args);
			
		if (!args.t) {
			args.t = screen.height / 2 - args.h / 2;
		}
		if (!args.l) {
			args.l = screen.width / 2 - args.w / 2;
		}
		if (args['wintype'] == '_top') {
			args.win.location.href = urlstr;
		}
		else {			
			open(
			urlstr,
			args['wintype'],
			'width=' + args.w + ',height=' + args.h + ',top=' + args.t + ',left=' + args.l + ',scrollbars,resizable'
			);
		
		}
		return;
	},
	
	qs :
	function(args) {
		args = jQuery.extend({
			ret : 'string',
			win : window
		},
		args);
		
		if (args['ret'] == 'string') {
			return jQuery.jqURL.url({ win:args.win }).split('?')[1];
			}

		else if (args['ret'] == 'object') {
			
			var qsobj = {};
			var thisqs = jQuery.jqURL.url({ win:args.win }).split('?')[1];
			
			if ( thisqs ) {
				var pairs = thisqs.split('&');
				for ( i=0;i<pairs.length;i++ ) {
					var pair = pairs[i].split('=');
					qsobj[pair[0]] = pair[1];
				}
			}
			return qsobj;
		}
	},
	
	strip :
	function(args) {
		args = jQuery.extend({
			keys : '',
			win : window
			},
			args);
		
		if (jQuery.jqURL.url().indexOf('?') == -1) { // no query string found
			return jQuery.jqURL.url({ win:args.win });
		}
		// if no keys passed in, just return url with no querystring
		else if (!args.keys) {
			return jQuery.jqURL.url({ win:args.win }).split('?')[0];
		}
		else { //return stripped url

			var qsobj = jQuery.jqURL.qs({ ret:'object',win:args.win });  // object with key/value pairs		
			var counter = 0;
			var url = jQuery.jqURL.url({ win:args.win }).split('?')[0] + '?';
			var amp = '';
			
			for (var key in qsobj) {
				if (args.keys.indexOf(key) == -1) { 
					// pass test, add this key/value to string
					amp = (counter) ? '&' : '';
					url = url + amp + key + '=' + qsobj[key];
					counter++;
				}
			}
			return url;
		}			
	},
	
	get :
	function(key,args) {
		args = jQuery.extend({
			win : window
			},args);
	
	qsobj =  jQuery.jqURL.qs({ ret:'object', win:args.win });
	return qsobj[key];
	},
	
	set :
	function(hash,args) {
		args = jQuery.extend({
			win : window
			},args);
		
		// get current querystring
		var qsobj =  jQuery.jqURL.qs({ ret:'object',win:args.win });
		
		// add/set values from hash
		for (var i in hash) {
			qsobj[i] = hash[i];
		}
		
		var qstring = '';
		var counter = 0;
		var amp = '';
		
		// turn qsobj into string
		for (var k in qsobj) {
			amp = (counter) ? '&' : '';
			qstring = qstring + amp + k + '=' + qsobj[k];
			counter++;
		}
		return jQuery.jqURL.strip({ win: args.win }) + '?' + qstring;
	}
	
};



