$(document).ready(function(){
		var x=document.getElementsByName("img_gall");
		var yc=getElementsByClassName("post");
		var nggspic=getElementsByClassName("ngg-singlepic");
		yc_len=yc.length;
                $("a").attr({ target: "_blank"});
		$("#navigation a").attr({ target: "_top"});
		$("#logo a").attr({ target: "_top"});
		$("#header_logo a").attr({ target: "_top"});
		$(".flexipages_widget ul li a").attr({ target: "_top"});
		$(".polls").attr({ target: "_top"});
		$(".this").attr({ target: "_top"});
		
		var spn = 0;
		if (nggspic.length > 0) {
			spn = 1;
		}
		else {
			spn = 0;
		}
		var i = spn;
        if (x.length >1){
		var xhre = x[spn].href;
        $(".contentas").empty();
		var bigp = '<a href="' + xhre + '" target="_blank">Download larger photo</a>';
        //var pic = "<img id='largeImg' src=' x[1].href ' x[1].title />";
		$("#content_l").empty().html('<p style="margin:300px 400px 300px 400px"><img src="http://glambabes.org/wp-content/themes/pink/images/loading.gif" /></p>');
		$("#bigpic_link").empty().html(bigp);
        //$(".contentas").empty().html(pic);
		//var hg = setHeight(x[i].href);
		//var wd = setWidth(x[i].href);
        //$("#largeImg").attr({ src: x[1].href, alt: x[1].title});

            var img = new Image();
            img.src = x[spn].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 = 930; 
               var maxh = 1200;    
               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); 
                   hig = newh;  wid = maxw;
               }
               if(hig > maxh){
                   ratio = maxh / hig; 
                   $(this).css("height", maxh);   
                   $(this).css("width", wid * ratio);   
               }

               $(this).fadeIn();
            }).error(function () {
                
            }).attr({ src: x[spn].href, id: 'largeImg', title: "Next Photo >>"/*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 hrf;
			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;				
				/*if (largePath == aa[ij].href) {
					//alert(aa[ij].href); 
					aa[ij].href=aa[0].href; 
					alert(aa[0].href);
					break;
				}*/
				ii++;
			}
			
	});
//------------------------------------------------------------
	$(".ngg-gallery-thumbnail a").click(function(){
	
            var largePath = $(this).attr("href");
			var largeAlt = $(this).attr("title");
			i = spn;
			while (largePath != x[i].href) {i++;}
			ig = x[i];
            $("#content_l").empty().html('<p style="margin:300px 400px 300px 400px"><img src="http://glambabes.org/wp-content/themes/pink/images/loading.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 = 930; 
               var maxh = 1200;    
               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);   
                   hig = newh;  wid = maxw;
               }
               if(hig > maxh){
                   ratio = maxh / hig; 
                   $(this).css("height", maxh);   
                   $(this).css("width", wid * ratio);   
               }

               $(this).fadeIn();
            }).error(function () {
                
            }).attr({ src: x[i].href, id: 'largeImg', title: "Next Photo >>"/*x[1].title*/ });            
          
		var bigp = '<a href="' + x[i].href + '" target="_blank">Download larger photo</a>';
        $("#bigpic_link").empty().html(bigp);
		
		return false;
	});
  //------------------------------------------------------------
 	$(".contentas").click(function(){
			if (i+1 == x.length)
			{i = spn;}
			else
			{i++;};
			
			
            $("#content_l").empty().html('<p style="margin:300px 400px 300px 400px"><img src="http://glambabes.org/wp-content/themes/pink/images/loading.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 = 930; 
               var maxh = 1200;    
               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); 
                   hig = newh;    wid = maxw;
               }
               if(hig > maxh){
                   ratio = maxh / hig; 
                   $(this).css("height", maxh);   
                   $(this).css("width", wid * ratio);   
               }
               $(this).fadeIn();
            }).error(function () {
                //notify the user that the image could not be loaded
            }).attr({ src: x[i].href, id: 'largeImg', title: "Next Photo >>"/*x[1].title*/});
          //largeAlt="glambabes.org";
		  var bigp = '<a href="' + x[i].href + '" target="_blank">Download larger photo</a>';
        $("#bigpic_link").empty().html(bigp);
	 // $("h2 em").html(" (" + largeAlt + ")"); return false;
	});
//------------------------------------------------------------
	$(".ngg-singlepic").click(function(){
	  var tot=document.getElementById("single");
		if (tot) {return false;}
	});
    
});