$(document).ready(function(){

		var x=document.getElementsByName("img_gall");
		var yc=getElementsByClassName("post");
		yc_len=yc.length;
                $("a").attr({ target: "_blank"});
		$("#navigation a").attr({ target: "_top"});
		$("#logo a").attr({ target: "_top"});
		$("#single_logo a").attr({ target: "_top"});
		//$(".like").attr({ target: "_top"});
		//$(".liked").attr({ target: "_top"});
		//$(".unlike a").attr({ target: "_top"});
		$(".wp_likes a").attr({ target: "_top"});
		$(".flexipages_widget ul li a").attr({ target: "_top"});
		$(".ngg-gallery-thumbnail a").attr({ target: "_blank"});
		$(".this").attr({ target: "_top"});
		var i = 1;
        if (x.length >1){
        var xhre = x[1].href;
        $(".contentas").empty();
        //var pic = '<img id="largeImg" src="http://pierbabes.com/wp-content/themes/pink/images/ajax-loader.gif" title="loading" />';
        var bigp = '<a href="' + xhre + '" target="_blank">Download larger photo</a>';
        //$(".contentas").empty().html(pic);
$("#content_l").empty().html('<p style="margin:234px 384px 234px 384px"><img src="http://pierbabes.com/wp-content/themes/pink/images/ajax-loader.gif" /></p>');
        $("#bigpic_link").empty().html(bigp);
      //  $("#largeImg").attr({ src: x[1].href, title: x[1].title, width:800, height:500 });

            var img = new Image();
            img.src = x[1].href;
            $(img).load(function () {
               //$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
               //$(this).hide();
               $("#content_l").empty();
               $('#content_l').removeClass('contentas').append(this);
               
               var maxw = 800; 
               var maxh = 500;    
               var ratio = 0;  
               var wid = $(img).width();    
               var hig = $(img).height(); 
           
               if(wid > maxw){
                   ratio = maxw / wid;   
           
                   $(this).css("width", maxw);
                   var newh = hig * ratio;
                   $(this).css("height", newh);   
               }
               if(hig > maxh){
                   ratio = maxh / hig; 
                   $(this).css("height", maxh);   
                   $(this).css("width", wid * ratio);   
               }

               $(this).fadeIn();
            }).error(function () {
                
            }).attr({ src: x[1].href, id: 'largeImg', title: x[1].title });



	$("h2").append('<em></em>')
}
//------------------------------------------------------------	
function getElementsByClassName(searchClass, node, tag)
{
	var classElements = new Array();
	if (node == null)
	{
		node = document;
	}
	if (tag == null)
	{
		tag = '*';
	}
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
	for (var i = 0, j = 0; i < elsLen; i++)
	{
		if (pattern.test(els[i].className))
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

//------------------------------------------------------------
	$(".igall").click(function(){
	   
            var largePath = $(this).attr("href");
			var largeAlt = $(this).attr("title");

			var ii = 0;
			var k = 0;
			while (ii<yc_len) {
				var aa=yc[ii].getElementsByTagName("a");
				while (k<aa.length) {
					if (largePath == aa[k].href) {
						var cc=aa[k].getElementsByTagName("img");
						if (cc[0].className=='ngg-singlepic'){
							aa[k].href=aa[0].href; 
							break;
						}
					}
					k++; 
				}
				k=0;				
				
				ii++;
			}
	});
//------------------------------------------------------------
	$(".ngg-gallery-thumbnail a").click(function(){
            var largePath = $(this).attr("href");
			
			var largeAlt = $(this).attr("title");
			i = 1;
			while (largePath != x[i].href) {i++;}
			ig = x[i];
			$("#loadingbigpic").css('display', 'block');
            //$("#content_l").empty().html('<p style="margin:234px 384px 234px 384px"><img src="http://pierbabes.com/wp-content/themes/pink/images/ajax-loader.gif" /></p>');
            var img = new Image();
            img.src = x[i].href;
            $(img).load(function () {
               //$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
               //$(this).hide();
               $("#content_l").empty();
               $('#content_l').removeClass('contentas').append(this);
               
               var maxw = 800; 
               var maxh = 500;    
               var ratio = 0;  
               var wid = $(img).width();    
               var hig = $(img).height(); 
           
               if(wid > maxw){
                   ratio = maxw / wid;   
           
                   $(this).css("width", maxw);
                   var newh = hig * ratio;
                   $(this).css("height", newh);   
               }
               if(hig > maxh){
                   ratio = maxh / hig; 
                   $(this).css("height", maxh);   
                   $(this).css("width", wid * ratio);   
               }

               $(this).fadeIn();
			   $("#loadingbigpic").css('display', 'none');
            }).error(function () {
                
            }).attr({ src: x[i].href, id: 'largeImg', title: x[i].title });

        var bigp = '<a href="' + x[i].href + '" target="_blank">Download larger photo</a>';
        $("#bigpic_link").empty().html(bigp);
        //$(".largeLink").attr({ href: x[i].href });            
       
		return false;
	});
  //------------------------------------------------------------
 	$(".contentas").click(function(){
			if (i+1 == x.length)
			{i = 1;}
			else
			{i++;};
	
			$("#loadingbigpic").css('display', 'block');
            //$("#content_l").empty().html('<p style="margin:234px 384px 234px 384px"><img src="http://pierbabes.com/wp-content/themes/pink/images/ajax-loader.gif" /></p>');
            var img = new Image();
            $(img).load(function () {
               
               //$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
               //$(this).hide();
               $("#content_l").empty();
               $('#content_l').removeClass('contentas').append(this);
                              var maxw = 800; 
               var maxh = 500;    
               var ratio = 0;  
               var wid = $(img).width();    
               var hig = $(img).height(); 
           
               if(wid > maxw){
                   ratio = maxw / wid;   
           
                   $(this).css("width", maxw);
                   var newh = hig * ratio;
                   $(this).css("height", newh);   
               }
               if(hig > maxh){
                   ratio = maxh / hig; 
                   $(this).css("height", maxh);   
                   $(this).css("width", wid * ratio);   
               }
               $(this).fadeIn();
			   $("#loadingbigpic").css('display', 'none');
            }).error(function () {
                //notify the user that the image could not be loaded
            }).attr({ src: x[i].href, id: 'largeImg', title: x[i].title});


        var bigp = '<a href="' + x[i].href + '" target="_blank">Download larger photo</a>';
        $("#bigpic_link").empty().html(bigp);
        //$(".largeLink").attr({ href: x[i].href, title: x[i].title});
return false;
	});
//------------------------------------------------------------
	$(".ngg-singlepic").click(function(){
	  var tot=document.getElementById("single");
		if (tot) {return false;}
	});


    
});
