
$(document).ready(function(){

var themedirectory = 'http://ww.tr.se/tr/wp-content/themes/tr2/images/';

// ============================= 
// ! HIDE/SHOW GALLERY SUBMENU   
// ============================= 

	$("ul#navigation ul").hide();
	if ($("ul#navigation li").hasClass("current_page")) {
		$("ul#navigation ul").show();	
	}

// =============================== 
// ! POSITION IMAGES ABOVE TITLE   
// =============================== 

	$('#uppsnappat li').each (function(k){
		$('#uppsnappat h3:eq('+k+')').css("padding-top", $('#uppsnappat ul li:eq('+k+') img').outerHeight());
		$('#uppsnappat li img').css({"position":"absolute", "top":"5px"});			
	});
	
	
	
// =================== 
// ! INIT UPPSNAPPAT   
// =================== 
	
	$('#uppsnappat ul').gridLayout('#uppsnappat ul li' ,{col_width: 155, min_cols: 2});

	$('#uppsnappat ul').gridLayout.placeAtEnd($('#final_block'));
	if ($('#final_block').position()) {
		$('#uppsnappat').css('height', $('#final_block').position().top);
	}
	$('#uppsnappat ul').bind( "gridchange", function(e){
		//$('#uppsnappat ul').gridLayout.placeAtEnd($('#final_block'));
		//$('#uppsnappat').css('height', $('#final_block').position().top);
	});	
	
		
		
// ============================= 
// ! HOVER GRID LAYOUT INSIDAN   
// ============================= 
	
	var orginalbgrA = $('#uppsnappat ul li:eq(2)').css("background-color");
	$('#uppsnappat ul li').not($('#uppsnappat ul li:first')).hover(
		function() {
			//alert('apa');
		    //if ($(this) != $('#wrap ul li:first-child')) 
		    $(this).animate({backgroundColor:"#E2FC8C"}, 200); // b5e1ff
		},
		function() {
			$(this).animate({backgroundColor:orginalbgrA}, 400);
	});	
	
		
	
// ============================= 
// ! HOVER GALLERY   
// ============================= 
	
	var orginalbgrC = $('#showcasegallery>ul>li').css("background-color");
	$('#showcasegallery>ul>li').hover(
		function() {
			//alert('apa');
		    //if ($(this) != $('#wrap ul li:first-child')) 
		    $(this).animate({backgroundColor:"#222"}, 200); // b5e1ff
		},
		function() {
			$(this).animate({backgroundColor:orginalbgrC}, 400);
	});		

// ============================= 
// ! HOVER PROFILES   
// ============================= 
	

//	var orginalbgrB = $('#profiles ul li').css("background-color");
	$('#profiles ul li').hover(
		function() {
		    $(this).css("background-color","#E2FC8C");/* find("a"). */
		},
		function() {
		    $(this).css("background-color","#fff");
	});

	
		
// =========== 
// ! GALLERY   
// =========== 

	$("ul.gallery li br").remove(); //bort med alla <br>
	
// ============================================= 
// ! SET SAME HEIGHT ON ALL GALLERY LIST ITEMS   
// ============================================= 


var gallerymaxheight = null;
$('#showcasegallery>ul>li').each(function() {
	if ( !gallerymaxheight || gallerymaxheight < $(this).height() )
	gallerymaxheight = $(this).height();
});
	
$('#showcasegallery>ul>li').each(function() {
	$(this).height(gallerymaxheight);
});

// ============ 
// ! FANCYBOX   
// ============ 

	$("#uppsnappat a>img").parent().attr("class", "fancy_single_image");
	$("#blog a>img").parent().attr("class", "fancy_single_image");
	$("#blog .tweet_this img").parent().removeAttr("class");
	
	$("a.fancy_single_image").fancybox();
	
	$("a.fancy_iframe").fancybox({
		"frameWidth": 800,
		"frameHeight":500,
		'hideOnContentClick': false 	
	});	

	$("a.fancy_gallery").fancybox({
		"frameWidth": 900,
		"frameHeight":600,
		'hideOnContentClick': false
	});	

	//$("object").fancybox();
	
	
// ====================== 
// ! CLICKABLE PROFILES   
// ====================== 

	$("#profiles ul:first-child li").css("cursor", "pointer");

	var orgBorderColor = $("#profiles ul:first-child li img").css("border-color");
	$("#profiles ul:first-child li").hover(function(){ 
		$(this).find("img").css("border-color", $(this).find("a").css("color")); //same as link-color
	},function(){ 
		$(this).find("img").css("border-color", orgBorderColor); 
	});
	
	$("#profiles ul:first-child li").click( function () {
		//alert($(this).find("a").attr("href"));
		window.location = $(this).find("a").attr("href");
		return false;		
	});	

});

	
	