
$(document).ready(function(){

	/*$('.comment_share_f').live('click', function(){
		var url = 'http://www.facebook.com/sharer.php?u='+$(this).attr('href');
		url = (url.substr(-1,1)=='/') ? url.substring(0,url.length-1) : url ;
		window.open(url,'','scrollbars=no,menubar=no,height=500,width=600,resizable=no,toolbar=no,location=no,status=no');
		return false;
	});*/

	/*$('.firstcheck').click(function() {
		//alert($(this).val());
		$(this).attr("checked", !$(this).attr("checked")); 
		return false;
	});*/

	$("p.hide").remove();

	$('.clean').clearField();
	
	$('a.thickbox').thickbox({
		inlineId: 'feedback',
		modal: false,
		width: 737,
		height: 479
	});
	
	$('#submit-search').hover(
		function(){
		$(this).attr('src','http://www.barnperspektivet.se/wp-content/themes/sandbox/lib/img/sok_knapp_mo.png');
		},
		function(){
		$(this).attr('src','http://www.barnperspektivet.se/wp-content/themes/sandbox/lib/img/sok_knapp.png');
		}
	);
	$.fn.addHover = function() { 
		return this.each(function() {
			$(this).hover(
				function(){
					$(this).addClass('hovering');
				},
				function(){
					$(this).removeClass('hovering');
				}
			);
		});
	};
	$('#menu li, .sidebar_ad').addHover();
	$('#menu li:last').addClass('lastItem');
	$('#menu li:first').hover(
		function() {
		$(this).addClass('firstItem');
		},
		function() {
		$(this).removeClass('firstItem');	
		}
	);
	$('.knapp').hover(
		function(){
			$(this).parent().addClass('hovering');
		},
		function(){
			$(this).parent().removeClass('hovering');
		}	
	);
	
	$('.edit:last').css('margin-bottom', '5px');
	$('#submit').click(function(){
		if ($('#comment').val() == '') {
			$('#errormsg').html('Du måste fylla i en kommentar först!');
			return false;
		} else {
			return true;
		}
	});
	
	var current_page_last = $('#menu li.page_item:last');
	var current_page_first = $('#menu li.page_item:first');
	
	if (current_page_last.hasClass('current_page_item') || current_page_last.hasClass('current_page_ancestor')) {
		current_page_last.addClass('lastItem');
	};
	if (current_page_first.hasClass('current_page_item') || current_page_first.hasClass('current_page_ancestor')) {
		current_page_first.addClass('firstItem');
	};
	
	$("#goodbutton").click(function(){
		var pos = $(this).parent().attr('id').indexOf('_');
		var post = $(this).parent().attr('id').substr(pos+1);
		var votecookie = 'vote'+post;
		$.cookie(votecookie, 'true');
		$('#pollresult_'+post).load('http://www.barnperspektivet.se/wp-content/plugins/poll-function/pollreceiver.php?vote=1&post='+post);
		$('#pollbuttons_'+post).html('Tack för din åsikt!');
		return false;
	});
	
	$("#badbutton").click(function(){	
		var pos = $(this).parent().attr('id').indexOf('_');
		var post = $(this).parent().attr('id').substr(pos+1);
		var votecookie = 'vote'+post;
		$.cookie(votecookie, 'true');
		$('#pollresult_'+post).load('http://www.barnperspektivet.se/wp-content/plugins/poll-function/pollreceiver.php?vote=-1&post='+post);
		$('#pollbuttons_'+post).html('Tack för din åsikt!');
		return false;
	});
	
	$(".flag").click(function(){
		var pos = $(this).parent().attr('id').indexOf('_');
		var comment = $(this).parent().attr('id').substr(pos+1);
		$('#flag_'+comment).load('http://www.barnperspektivet.se/wp-content/plugins/checkflags/flagreceiver.php?comment='+comment);
		return false;
	});	
	
	$(".open_questionnaire").click(function(){
		window.open( "http://www.barnperspektivet.se/questionnaire/questionnaire.php", "Barnperspektivet - Tyck till", "status = 1, height = 500, width = 900, resizable = 0");
		return false;
	});
	
	$(".open_chat").click(function() {
		//window.open( "http://www.barnperspektivet.se/chat/chat.php", "Barnperspektivet - Chat", "status = 1, height = 700, width = 500, resizable = 0");
		window.open("http://www.barnperspektivet.se/chat/chat.php", "Barnperspektivet", "status = 1, height = 700, width = 500, resizable = 0");
		return false;
	});
	
	$("#send_questionnaire").click(function() {
		var q_id = $('#q_id').val();
		var multiple_choice_forms = $('#multiple_choice_forms').val();
		var free_text_forms = $('#free_text_forms').val();
		var sex = $('[name=sex]:checked').val();
        if (String(sex) == 'undefined') {
        	sex = 'unknown';
        }
		var age = $('[name=age]').val();
		
		var multiple_choice_answers = '';
		for (i=0; i<multiple_choice_forms; i++) {
			multiple_choice_answers = multiple_choice_answers + $('[name=radio_'+i+']:checked').val()+'¤';
		}
		
		var free_text_answers = '';
		for (i=0; i<free_text_forms; i++) {
			free_text_answers = free_text_answers + $('[name=text_'+i+']').val().replace('¤', '') + '¤';
		}
		
		var dataString = 'q_id='+q_id+'&multiple_choice_answers='+multiple_choice_answers+'&free_text_answers='+free_text_answers+'&sex='+sex+'&age='+age;
		
		$.ajax({
			type:"GET",
			url:"http://www.barnperspektivet.se/questionnaire/sendquestionnaire.php?rnd="+Math.random(),
			data:dataString,
			cache:false,
			success: function(html){
				$('#replaceable').html('Tack för din medverkan!');
                $('.section').find('p').html('');
			}
		});
		
		return false;
        
	});
	
	
	
	$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().children().children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0 || $.browser.version == 8.0) { $(this).children().children().children().css({'height': currentTallest}); }
		$(this).children().children().children().css({'min-height': currentTallest}); 
	});
	return this;
	};

	$('.lista_teman').equalHeights();
	
	
	
	
	
	
	
	
/*var $panels = $('#slider .scrollContainer > div');
var $container = $('#slider .scrollContainer');
var horizontal = false;

if (horizontal) {
  $panels.css({
    'float' : 'left',
    'position' : 'relative'
  });
	$container.css('width', $panels[0].offsetWidth * $panels.length);
}
var $scroll = $('#slider .scroll').css('overflow', 'hidden');

$scroll
  .before('<img class="scrollButtons left" src="http://www.barnperspektivet.se/wp-content/themes/sandbox/lib/img/scroll_left.png" alt=Nästa" />')
  .after('<img class="scrollButtons right" src="http://www.barnperspektivet.se/wp-content/themes/sandbox/lib/img/scroll_right.png" alt=Nästa" />');
  
// handle nav selection
function selectNav() {
  $(this)
    .parents('ul:first')
      .find('a')
        .removeClass('selected')
      .end()
    .end()
    .addClass('selected');
}

$('#slider .navigation').find('a').click(selectNav);

// go find the navigation link that has this target and select the nav
function trigger(data) {
  var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
  selectNav.call(el);
}

if (window.location.hash) {
  trigger({ id : window.location.hash.substr(1) });
} else {
  $('ul.navigation a:first').click();
}

// offset is used to move to *exactly* the right place, since I'm using
// padding on my example, I need to subtract the amount of padding to
// the offset.  Try removing this to get a good idea of the effect
var offset = parseInt((horizontal ? 
  $container.css('paddingTop') : 
  $container.css('paddingLeft')) 
  || 0) * -1;


var scrollOptions = {
  target: $scroll, // the element that has the overflow
  
  // can be a selector which will be relative to the target
  items: $panels,
  
  navigation: '.navigation a',
  
  // selectors are NOT relative to document, i.e. make sure they're unique
  prev: 'img.left', 
  next: 'img.right',
  
  // allow the scroll effect to run both directions
  axis: 'xy',
  
  onAfter: trigger, // our final callback
  
  offset: offset,
  
  // duration of the sliding effect
  duration: 500,
  
  // easing - can be used with the easing plugin: 
  // http://gsgd.co.uk/sandbox/jquery/easing/
  easing: 'swing'
};

// apply serialScroll to the slider - we chose this plugin because it 
// supports// the indexed next and previous scroll along with hooking 
// in to our navigation.
$('#slider').serialScroll(scrollOptions);

// now apply localScroll to hook any other arbitrary links to trigger 
// the effect
$.localScroll(scrollOptions);

// finally, if the URL has a hash, move the slider in to position, 
// setting the duration to 1 because I don't want it to scroll in the
// very first page load.  We don't always need this, but it ensures
// the positioning is absolutely spot on when the pages loads.
scrollOptions.duration = 1;
$.localScroll.hash(scrollOptions);*/

    $('#alla').css('display', 'block');

	$('.navigation').find('a').click(function() {
    	if ($(this).attr('href') != '#alla') {
		$('.panel').css('display', 'none');
    	var div = $(this).attr('href');
        $(div).fadeIn("slow");
        }
        return false;
	});
    
    $('.back').click(function() {  
    	$('.panel').css('display', 'none');
        $('#alla').fadeIn("slow");
        return false;
    });
    
    $("#middle_footer_column a").each(function () {
		if ($(this).html().search('Facebook') != -1) {
        	$(this).addClass('footer_facebook');
        } else if ($(this).html().search('RSS') != -1) {
        	$(this).addClass('footer_rss');
        }
	});
    
    $('.large_like').click(function() {  
    	alert('test');
		/*$(this).css('width', '180px');
        $(this).css('height', '16px');*/
    });
    
    
	$("#article_filter_step1 select").change(function(){
		$('#article_filter_step1').submit();
		return false;
	});	
    
	$("#article_filter_step2 select").change(function(){
		$('#article_filter_step2').submit();
		return false;
	});	
	
});



