$(document).ready(function() {
  //global
  
  $("#nav li").hover(
    function(){ $("ul", this).show(); },
    function(){ $("ul", this).hide(); }
  );
  
  $("#nav li ul").each(function(){
    $(this).find("li:last").css("borderBottom", "0");
  });
  
  //home
  if(typeof current_location != "undefined" && current_location == "home") {
    $('#home-gallery-list img').each(function(){
      $(this).wrap('<table class="center"><tr><td></td></tr></table>');
    });
  
//     $('#sample-gallery').jcarousel({
//       scroll:8,
//       wrap:"both"
//     });
  
//     $('.jcarousel-item img').each(function(){
//       $(this).wrap('<table><tr><td></td></tr></table>');
//       if (use_image_previews == 0) {
//         $(this).click(function(){
//           location.href = $(this).parent().parent().parent().parent().parent().attr('href');
//         });
//       }
//     });
    
    $('#home-forums ul li img').click(function(){
      $(this).toggleClass("contract");
      $(this).nextAll().toggle();
    });

    if (use_image_previews) {        
      $('#sample-gallery a').click(function(){
        id = $(this).find("img").attr("id").split("-")[1];
        $('#sample-zoom #sample-image').attr("src", sample_gallery[id][6]);
        $('#sample-zoom #sample-image-link').attr("href", '/photodb/photo?photo_id=' + sample_gallery[id][3]);
        $('#sample-zoom #sample-image').removeAttr("width");
        $('#sample-zoom #sample-image').removeAttr("height");
        $('#sample-zoom h3').text(sample_gallery[id][0]);
        $('#sample-zoom h4').html('By: <a href="/photodb/user?user_id=' + sample_gallery[id][2] + '">' + sample_gallery[id][1] + '</a>');
        $('#sample-zoom p').html('<a href="/photodb/photo?photo_id=' + sample_gallery[id][3] + '">View Image</a> | <a href="' + sample_gallery[id][4] + '">Critique Photo</a> | <a href="/photodb/member-photos?user_id=' + sample_gallery[id][2] + '">View Portfolio</a> (' + sample_gallery[id][5] +' images)');
        $('#sample-zoom').fadeIn('fast');
        return false;
      });
    }
  }
});

// ecomm
if(typeof current_location != "undefined" && current_location == "ecomm") {
  $(document).ready(function(){
    $('#cczoom a').click(function(){
      $('#ecomm-zoom').fadeIn();
      return false;
    });
  });
};

// generic fadein
$(document).ready(function(){
  $('.open').click(function(){
    $('#' + $(this).attr('id') + '-wrap').fadeIn();
    return false;
  });
  $('.close').click(function(){
    $(this).parent().parent().fadeOut();
    return false;
  });
});
  
// tab widget above filter form on search photographers page
function getElementsByClass(objArea, thisTag, thisClass) {
	var obj = document.getElementById(objArea).getElementsByTagName(thisTag);
	var arrElements = new Array();
	for (i = 0; i < obj.length; i++) {
				if(obj[i].className == thisClass) {
							arrElements[arrElements.length] = obj[i]
				}
	}
	return arrElements;
}

function showWidget(tab,objNum) {
	var objTab = document.getElementById($elID);
//	var objTab = document.getElementById("wTabs");
	objTab = objTab.getElementsByTagName($tagName);
//	objTab = objTab.getElementsByTagName("li");
	var objContent = getElementsByClass($holder, $domPart, $switchPart);
//	var objContent = getElementsByClass("searchbar", "div", "formbody");
	for (i = 0; i < objTab.length; i++) {
		if (i == tab) {
			objTab[i].className = "on";
			objContent[i].style.display = "block";
		} else {
			objTab[i].className = "";
			objContent[i].style.display = "none";
		}
	}
}


// toggle admin options on individual portfolio page
$(document).ready(function(){
	$("p.opener a").click(function(){
		                $(".admin-options").toggle();
		                return false;
	                      });
	$("a.closer").click(function(){
		              $(".admin-options").hide();
		              return false;
	                    });
});

// toggle details on individual portfolio
$(document).ready(function(){
	//show all details
    if ($.cookie("folder-details-pref") == "expanded") {
		$(".phdetails").slideToggle(500);
		$('span.toggle-off').show();
		$('span.toggle-on').hide();
    }
    
	$(".show_details").click(function(){
		$(".phdetails").slideToggle(500);
        if ($.cookie("folder-details-pref") == "expanded") {
            $.cookie("folder-details-pref", "collapsed");
        } else {
            $.cookie("folder-details-pref", "expanded");    
        }
		return false;
	});
	// toggle the show/hide link
	$('span.toggle-on > a.show_details').click(function(){
		$('span.toggle-off').show();
		$('span.toggle-on').hide();
		return false;
	});
	$('span.toggle-off > a.show_details').click(function(){
		$('span.toggle-on').show();
		$('span.toggle-off').hide();
		return false;
	});
});

// toggle infoboxes on forums list
function toggleLayer(whichLayer) {
  var elem, vis;
  if(document.getElementById) // this is the way the standards work
    elem = document.getElementById(whichLayer);
  else if(document.all) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if(document.layers) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
