(function($) {
	//for left column and global poll
	$.fn.JloadPoll = function(options) {
		return this.each(function() {
			var pollContainer, pollPath, pollid;
			if($(this).is('[name="pollform"]')){
				pollContainer	= $(this).parent("div");
				pollPath 		= $(this).attr("action");
				$('[name="pollform"] [name="poll_vote"]').bind('click', function() {
					var path = $(this).parents('form').attr('action');
					
					$.get(path, { poll_choice: $('[name="poll_choice"]:checked').val(), id: $('[name="id"]').val(), __toolbar: "0", __xsl: $('[name="__xsl"]').val(), poll_vote: "1"}, function(data){
						pollContainer.html(data);
					});
					return false;
				});
			}
			else{
				pollContainer 	= $(this).children('div');
				if($(this).is(".pollfeature")) {
					pollPath = "/index.xml";
					pollid = "rightcol";
				}
				else {
					pollPath = $(this).children('div').children('p').html(); //"/index.xml";
					pollid = $(this).attr("id");
				}
		
				$.get(pollPath, { __xsl: "/templates/components/poll-comp-render.xsl", __toolbar: "0", id: pollid}, function(data){
					pollContainer.html(data);
					$('.pollfeature button').wrap('<span class="button"></span>');
					
					//attach click event!
					$('[name="poll_vote"]').bind('click', function() {
						var path = $(this).parents('form').attr('action');
						var updateContainer = $(this).parents('form').parent('div:first');
						$.get(path, { poll_choice: $('[name="poll_choice"]:checked').val(), id: $('[name="id"]').val(), __toolbar: "0", __xsl: $('[name="__xsl"]').val(), poll_vote: "1"}, function(data){
							updateContainer.html(data);
						});
						return false;
					});
				});
			}
		});
	}
	
})(jQuery);



jQuery(function($) {	
	$('.pollfeature').JloadPoll();
	$('.poll').JloadPoll();
});
//jQuery.noConflict();
jQuery(window).bind('unload', function() { jQuery('*').unbind(); });

		
		
		jQuery(document).ready(function(){
		
		jQuery.noConflict();
		RunPictureCollInits();
			
			// LÄSARTOPPEN		
			jQuery(".oneweek").addClass("active");
		
			jQuery(".oneday").click(function(){
				jQuery("#most-read-oneday").animate({ opacity: "show" }, "fast");
				jQuery("#most-read-oneweek").animate({ opacity: "hide" }, "fast");
				jQuery(".oneweek").removeClass("active");
				jQuery(this).addClass("active"); return false;
			});
			
			jQuery(".oneweek").click(function(){
				jQuery("#most-read-oneweek").animate({ opacity: "show" }, "fast");
				jQuery("#most-read-oneday").animate({ opacity: "hide" }, "fast");
				jQuery(".oneday").removeClass("active");
				jQuery(this).addClass("active"); return false;
			});
			
			
			// Stockholmsbörsen idag
			jQuery(".large").addClass("active");
		
			jQuery(".large").click(function(){
				jQuery("#large_cap").animate({ opacity: "show" }, "fast");
				jQuery("#mid_cap").animate({ opacity: "hide" }, "fast");
				jQuery("#small_cap").animate({ opacity: "hide" }, "fast");
				jQuery(".mid").removeClass("active");
				jQuery(".small").removeClass("active");
				jQuery(this).addClass("active"); return false;
			});
			
			jQuery(".mid").click(function(){
				jQuery("#mid_cap").animate({ opacity: "show" }, "fast");
				jQuery("#large_cap").animate({ opacity: "hide" }, "fast");
				jQuery("#small_cap").animate({ opacity: "hide" }, "fast");
				jQuery(".large").removeClass("active");
				jQuery(".small").removeClass("active");
				jQuery(this).addClass("active"); return false;
			});				
				
			jQuery(".small").click(function(){
				jQuery("#small_cap").animate({ opacity: "show" }, "fast");
				jQuery("#large_cap").animate({ opacity: "hide" }, "fast");
				jQuery("#mid_cap").animate({ opacity: "hide" }, "fast");
				jQuery(".mid").removeClass("active");
				jQuery(".large").removeClass("active");
				jQuery(this).addClass("active"); return false;
			});
			
			<!-- COMMENT RULES -->
			jQuery("#comment-rules").click(function(){
				jQuery("#comment-rules-box").animate({ opacity: "show" }, "fast"); return false;				
			});	
			jQuery("#comment-rules-close").click(function(){
				jQuery("#comment-rules-box").animate({ opacity: "hide" }, "fast"); return false;				
			});	
			
			<!-- TAGGAR -->
			jQuery(".tag-head").click(function(){
				jQuery(this).next(".tag-body").slideToggle(500)
		        jQuery(this).toggleClass("tag-active");
		        return false;
		    });

			
		});
		
		
		function showCellsByClass(classname) {
			var displayStyle = getDisplayStyle();
			//alert('showing class:'+classname+' as style:'+displayStyle);

			var classes = getElementsByClassName(classname);

			//var colgroupElmColl = document.getElementsByTagName("colgroup");
			
			//var colItemClass, classArr;
			//for(var i=0, colitem;colitem=colgroupElmColl[i];i++){
			//colItemClass = colitem.className;
			//classArr = colgroupElmColl.split(" ");
			//if(/history/i.test(colitem.className)){
			//	colitem.className += " colgroup-visible"; 
			//}
				
			//colitem.className = classArr[0];
				
			
			//}

			//alert('Det finns ' + classes.length + ' element med klassnamn: '+ classname );

			for(i=0;i<classes.length;i++) {
				//var displayStyle;
				//if(navigator.appName == "Microsoft Internet Explorer") { displayStyle = 'block';}
				//else { displayStyle = 'table-cell'}
				classes[i].style.display = displayStyle;
			}

		}
		function hideCellsByClass(classname) {

			var classes = getElementsByClassName(classname);

			//alert('Det finns ' + classes.length + ' element med klassnamn: '+ classname );

			for(i=0;i<classes.length;i++) {
				classes[i].style.display = 'none'
			}

		}

		function getDisplayStyle() {
			if(navigator.appName == "Microsoft Internet Explorer") { return 'block';}
			else { return 'table-cell'}
		}


		function getElementsByClassName(className, tag, elm){
			var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
			var tag = tag || "*";
			var elm = elm || document;
			var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
			var returnElements = [];
			var current;
			var length = elements.length;
			for(var i=0; i<length; i++){
				current = elements[i];
				if(testClass.test(current.className)){
					returnElements.push(current);
				}
			}
			return returnElements;
		}


//Handler for all onclick event (the regular onclick event is still executed after this though).
			document.onclick = function(e){

				//tab delegation
				//This assumes the following structure for the tabs:
				//<ul class="tabs"><li><a href=...><a><li>...</ul>
				//Where the event captured here is the onclick from the <a>-tag
				if(EventDelegation.GetTarget(e).parentNode.parentNode.className == "tab-list"){
					var ulList = EventDelegation.GetTarget(e).parentNode.parentNode;
					//var ulList = document.getElementById("tab-list");
					var linodes = ulList.getElementsByTagName("li");
					for(var i=0,liitem; liitem = linodes [i]; i++){
						liitem.className = "";
					}
					EventDelegation.GetTarget(e).parentNode.className = "selected";
					//alert("class="+EventDelegation.GetTarget(e).parentNode.className);
				}
			}

			var EventDelegation = {
				GetTarget : function(e){
					e = e || window.event;
    				return e.target || e.srcElement;
				}
			}
