// JavaScript Document

jQuery(document).ready(function() {

// Alter linkstyle in News
jQuery('img').parent('a').css({
	'border' : 'none',
	'padding' : 0
});

// ScrollFollow
// Gallery
var sF_height_gallery = jQuery('#gallery-thumb-wrapper').innerHeight();
jQuery( '#gallery-info-container' ).css('height', sF_height_gallery).children('#gallery-info').scrollFollow({
	speed: 600,
	offset: 40
});
// Kalendar
var sF_height_kalendar = jQuery('.content-kalendarium').innerHeight();
jQuery( '#kalendar-info-container' ).css('height', sF_height_kalendar).children('#kalendar-info').scrollFollow({
	speed: 600,
	offset: 40
});
//END: ScrollFollow
// Grabs the height from outer elem to dynamicly fit AVDELARE to it ––– SEE HOW jQuery() placed instead of value inside .css –––
jQuery('.content-kalendarium .column1 > .avdelare_kalendarium-border').css('height', jQuery('.content-kalendarium .column1').innerHeight());

// Ändrar "Svara" under Intervjuer
jQuery('.accordion_body > div > div > h3').text('Kommentera intervjun');	
	
//slides the element with class "accordion_body" when paragraph with class "accordion_head" is clicked
/*Bokmaskinen - Accordion*/
jQuery(".content-bokmaskinen p.accordion_head").click(function(){
	jQuery(this).toggleClass('accordionDownBlue').toggleClass('accordionForm').next("div.accordion_body").slideToggle(300).siblings("div.accordion_body").slideUp("slow");
	jQuery(this).siblings().removeClass('accordionDownBlue');    
});
/*END: Bokmaskinen - Accordion*/

/*Forum - Accordion*/
jQuery(".content-forum p.accordion_head").click(function(){
	jQuery(this).toggleClass('accordionDownOrange').toggleClass('accordionForm').next("div.accordion_body").slideToggle(300).siblings("div.accordion_body").slideUp("slow");
	jQuery(this).siblings().removeClass('accordionDownOrange');
});
/*END: Forum - Accordion*/

/*Pristabell*/
jQuery(".tbl-priser-bodysHeader").click(function(){
	jQuery(this).parents('.accordion_body').prev().toggleClass('accordionDownBlue').toggleClass('accordionForm').next("div.accordion_body").slideToggle(300).siblings("div.accordion_body").slideUp("slow");
	jQuery(this).siblings().removeClass('accordionDownBlue');
});
/*END: Pristabell*/

/*Biblioteket SÖK*/
jQuery("#label-filters, #label-sort, .form_submit").hover(function(){
	jQuery(this).toggleClass('hover-form'); /*color #333*/
});
jQuery("#label-filters, #label-sort").click(function(){
    jQuery(this).parent().toggleClass('accordionForm').next("div.accordion_body").slideToggle(300).removeClass('accordion_bodyFormAdvanced');
});

/* Ordna böcker efter: */
jQuery('.form-orderBy label').click(function(){
    /*clicks the input, this is an IE only, cant handle click on these Label:s*/
	if (jQuery(this).attr("for") != ""){
        jQuery("#" + jQuery(this).attr("for")).click();
	}
	/*Change button look onClick*/
	jQuery(this).addClass('form-button-down').siblings().removeClass('form-button-down');
	/*Submit Form*/
  	jQuery('#submit').trigger('click');

}).live('mouseover mouseout', function(event){
	/*Change button look onHover*/
	 if(event.type == 'mouseover'){
		jQuery(this).not('.nothover').addClass('form-button-down');
	}else{
		jQuery(this).not('.nothover').removeClass('form-button-down');
	}
});

jQuery('.form_submit').click(function(){
	/*IE needs this to trigger the submit label see problem in function above*/
	jQuery('#submit').trigger('click');
});

/* Filtrera sökning: */
jQuery('#wrapper-genre-language select, #wrapper-year-publisher select').change(function() {
	/*Submit Form*/
	jQuery('#submit').trigger('click');
});
/*END: Biblioteket SÖK*/

/*Intervjuer*/
jQuery(".content-intervjuer .accordion_head").click(function(){
	jQuery('.content-intervjuer .accordion_body').removeClass('display-intervju');
});

/*Kalendar MouseEvents*/
jQuery('.content-kalendarium p#eventName').bind({mouseenter: function(){
		jQuery('.content-kalendarium p#eventName > a').removeClass('yellowText');
		jQuery('> a', this).addClass('yellowText');
		jQuery('#kalendar-info > div').not('.' + jQuery(this).attr('class')).hide();
		jQuery('#kalendar-info .' + jQuery(this).attr('class')).fadeIn();
	}
});
/*END Kalendar MouseEvents*/

/*PoesiPED MouseEvents*/
jQuery('#latest-pped').bind('mouseenter', function() {
	jQuery("img", this).stop().animate({ 
		'maxWidth': 	'310px',
		'maxHeight': 	'470px'
	},200);
}).bind('mouseleave', function() {
	jQuery("img", this).stop().animate({ 
		'maxWidth': 	'300px',
		'maxHeight': 	'460px'
	},200);
});

jQuery('.old-pped').bind('mouseenter', function() {
	jQuery(".content-forum #firstpane").hide();
	jQuery("img", this).stop().animate({ 
		'maxWidth': 	'95px',
		'maxHeight': 	'155px'
	},300);
	jQuery('.poesiPED-info .' + jQuery(this).attr('id')).show();
}).bind('mouseleave', function() {
	jQuery("img", this).stop().animate({ 
		'maxWidth': 	'90px',	
		'maxHeight': 	'150px'
	},300);
	jQuery('.poesiPED-info .' + jQuery(this).attr('id')).hide();
	jQuery(".content-forum #firstpane").show();
});
/*END PoesiPED MouseEvents*/

/*Layoutgalleri MouseEvents*/
if( jQuery("#content").hasClass('content-layoutgalleri') ){
	var initWidth = jQuery('#layout-box > img').css('max-width');
	var initHeight = jQuery('#layout-box > img').css('max-height');	
	newWidth 	= 	initWidth.substring(0, 2) 	+ '5px';
	newHeight	=  	initHeight.substring(0, 2)	+ '5px'

	jQuery('#gallery-thumb-wrapper div').bind('mouseenter', function() {
	    jQuery("img", this).animate({
			'maxWidth': newWidth,
			'maxHeight': newHeight
		},0);
		jQuery('#gallery-header').hide();
		jQuery('#gallery-info .' + jQuery(this).attr('class')).fadeIn();
	}).bind('mouseleave', function() {
	    jQuery("img", this).animate({ 
			'maxWidth': initWidth,
			'maxHeight': initHeight
			},0);
	    jQuery('#gallery-info > div').hide();
		jQuery('#gallery-header').show();
	});
}

});
