// JavaScript Document
(function() {
    // Jquery Document
    $(document).ready(function() {
     
     // load the first thumbnail.
     var firstimg = $($('div.csc-textpic-imagewrap').children()[0]);
     firstimg = firstimg.find('a');
     firstimg = firstimg.attr("title")
     $('div.news-single-image img').attr({src:firstimg}).fadeIn("fast");
	 $.resizeImages($('div.news-single-image img'));

    // click function on thumbnails
        $('div.news-single-image-small a').click(function() {
            var newimg = this.title;
			//alert(newimg);
			$.preloadImages(newimg);

            $('div.news-single-image img').fadeOut("slow",function() {
			   $.removeAttrImages($(this));
               $(this).attr({src:newimg}).fadeIn("fast");
			   $.resizeImages($(this));
            });
           return true;
        });
    });
})();


jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {jQuery("<img>").attr("src", arguments[i]);}
}

jQuery.removeAttrImages = function(x)
{
	var pic = x;
	pic.removeAttr("width"); 
  	pic.removeAttr("height");
	x.removeAttr("width").removeAttr("height").css({ width: "", height: "" });
}

jQuery.resizeImages = function(x)
{
	var pic = x;	
	if  (pic.width() > pic.height() )
		{x.width(520)}
	else
		{x.height (340)}
			
  	//alert( pic.width() );
  	//alert( pic.height() );
}