var $ = jQuery.noConflict();
//Cufon
jQuery(document).ready(function($){ 
	Cufon.replace('.bulk h2, .bulk h3, .bulk h4, .bulk h5, #footer h5, #sub_footer h5, .blog_style .leaderboard h2 a, h1.titled, #the_team h2, #the_team cite, .single h1',{
    hover: true
	});
});

//Fix flash embed
jQuery(document).ready(function($){
    $("embed")
        .before('<param name="wmode" value="transparent">');
});


//Gallery
jQuery(document).ready(function($){ 
$('#gal').cycle({ fx: 'scrollHorz', speed:'600', timeout: 5000, next: '#next2', prev: '#prev2', easing: 'easeout' });
});

//Cols
jQuery(document).ready(function($){	
	$("#slider").easySlider ({
		prevText: 'Newer blog posts &laquo;',
		nextText: 'Older blog posts &raquo;',
		orientation: 'horizontal',
		speed: '200'
	});
});

//Tabs
jQuery(document).ready(function($) {
    $('#rotate > ul').tabs({ fx: { opacity: 'toggle' } });
});

//Flickr
jQuery(document).ready(function($){   
	jQuery("#gallery").flickr({     
	 api_key: "908e1657847346b6d3967bb608c76ef7",
	 type: "photoset",
	 thumb_size: 's', 
	 per_page: 3,
	 photoset_id: "72157621750422396",
	 size: "b"  
	}); 
});

jQuery(document).ready(function($){   
	jQuery("#gallery-long").flickr({     
	 api_key: "908e1657847346b6d3967bb608c76ef7",
	 type: "photoset",
	 thumb_size: 's', 
	 per_page: 39,
	 photoset_id: "72157621750422396",
	 size: "b"  
	}); 
});

//Truncate
jQuery(document).ready(function($){ 
	 $('.trunk').truncate({max_length: 550});
});

jQuery(document).ready(function($){ 
	 $('.trunk2').truncate({max_length: 270});
});

//Open in external windows
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

//Scale down images in posts
jQuery(document).ready(function($){ 
    $('.post_sing img').each(function() {
        var maxWidth = 580; // Max width for the image
        var maxHeight = 600;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = $(this).width();    // Current image width
        var height = $(this).height();  // Current image height
 
        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            $(this).css("width", maxWidth); // Set new width
            $(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
        }
 
        // Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            $(this).css("height", maxHeight);   // Set new height
            $(this).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
    });
});

//Banner display thing
jQuery(document).ready(function($){ 
   $("#type-size").change(function() {
       var graphicFileName = $("#type-size option:selected").attr("rel");
       var newCode = '<a href="http://www.igcp.org/"><img src="http://www.igcp.org/wp-content/themes/igcp/img/banners/' + graphicFileName + '" alt="Visit the IGCP" /></a>';
       $("#code-box").text(newCode);
       $("#graphic-example-area").html(newCode);
   });
});

/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
--------------------------------------------------------------------*/
jQuery(document).ready(function($){ 	
	function equalHeight(group) {
		tallest = 0;
		group.each(function() {
			thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}

	equalHeight($ ( "#slider .grid_4" ) );
	
});
