/* 
*   DC Comics scripts
*
*   addLoadEvent()   = queues an action to window.onload
*   newPage()          = adds a new page function to all tags with the class name "newpage" or "newpagemedia"
*
*/

function addLoadEvent(func) 
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } 
  else 
  {
    window.onload = function() 
    {
      oldonload();
      func();
    }
  }
}

function newPage() {
  if (!document.getElementsByTagName) return false;
  var links=document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) 
  {
    if ((links[i].className != null) && 
        (links[i].className == "newpage" || 
         links[i].className == "newpagemedia" ||
         links[i].className == "newpagehover")) 
    {
      links[i].onclick=function() 
      {
          window.open(this.href);
          return false;
      }
    }
  }
}

addLoadEvent(newPage);

/**
 * SINGLE LIST: Book cover/image rollover effects
 *
 */

$.fn.hover_default_image_set = function(elem) {
  $(elem).each(function() {
    href = $(elem).find(".cover_rollover:first").find("ul:first").find(".first a").attr("href");
    imgPath = $(this).find(".first a").attr("name");
    img = $('<img />').attr('src', imgPath).addClass('hoverImgWithLink');
    link = $('<a></a>').attr('href', href).addClass('hoverpic'); 
    $(elem).find(".cover_rollover:first").find("ul:first").before(img);   
    $(this).find(".hoverImgWithLink").wrap(link);
  });
}

$.fn.hover_effect = function(elem) {
  $(elem).each(function() {
    $(this).hover(function() {
        $(document.body).find(".cover_rollover").find(".hoverpic").remove();
        href = $(this).attr("href");
        imgPath = $(this).attr("name");
        newLink = $('<a></a>').attr('href', href).addClass('hoverpic');
        newImg = $('<img />').attr('src',imgPath).addClass('hoverImgWithLink');
        $(document.body).find(".cover_rollover:first").find("ul:first").before(newImg);
        $(document.body).find(".hoverImgWithLink").wrap(newLink);
      },
      function() {}
    );
  });
}



/**
 * MULTI-LIST (ACCORDION): Book cover/image rollover effects
 *
 */

$.fn.hover_default_image_set_accordion = function(elem) {
  $(elem).each(function() {
    href = $(this).next(".accordion").find(".first").find("a").attr("href");
    imgPath = $(this).next(".accordion").find(".first").find("a").attr("name");
    img = $('<img />').attr('src', imgPath).addClass('hoverImgWithLink');
    link = $('<a></a>').attr('href', href).addClass('hoverpic');
    $(this).next(".accordion").find("ul").before(img);
    $(this).next(".accordion").find(".hoverImgWithLink").wrap(link);
  });
}

$.fn.hover_effect_accordion = function(elem) {
  $(elem).each(function() {
    $(this).hover(
      function() {
        $(this).parent().parent().parent().find(".hoverpic").remove();
        href = $(this).attr("href");
        imgPath = $(this).attr("name");			
        newLink = $('<a></a>').attr('href', href).addClass('hoverpic');
        newImg = $('<img />').attr('src',imgPath).addClass('hoverImgWithLink');
        $(this).parent().parent().before(newImg);		$(this).parent().parent().parent().find(".hoverImgWithLink").wrap(newLink);
      },
      function() {}
    );
  });
}


$(document).ready(function() {
  $(this).hover_default_image_set("#graphic_novels.listview");
  $(this).hover_effect("#graphic_novels .cover_rollover ul li a");
});



// Left hand Navigation effects

jQuery(document).ready(function() {
  $(".nav-submenu > a").bind("click", function(event){
    $(this).parent(".nav-submenu").find("ul").animate({
      "height": "toggle", 
      "opacity": "toggle"
    }, { duration: "fast" });
    event.stopPropagation();
    return false;
  });	
});


// These control the tout-toggle functionality on the homepage 

jQuery(document).ready(function() {
	$("#div1 #btn-ppr a").click(function() {
		$("#div1 #div1-c1").show();
		$("#div1 #div1-c2").hide();
		$("#div1 #div1-nav #btn-ppr").css("background-color","#ED1C24");
		$("#div1 #div1-nav #btn-pxl").css("background-color","#666");
		return false;
	});
	$("#div1 #btn-pxl a").click(function() {
		$("#div1 #div1-c1").hide();
		$("#div1 #div1-c2").show();
		$("#div1 #div1-nav #btn-ppr").css("background-color","#666");
		$("#div1 #div1-nav #btn-pxl").css("background-color","#ED1C24");
		return false;
	});
	$("#div3 #btn-blog a").click(function() {
		$("#div3 #div3-c1").hide();
		$("#div3 #div3-c2").show();
		$("#div3 #div3-nav #btn-news").css("background-color","#666");
		$("#div3 #div3-nav #btn-blog").css("background-color","#ED1C24");
		return false;
	});
	$("#div3 #btn-news a").click(function() {
		$("#div3 #div3-c1").show();
		$("#div3 #div3-c2").hide();
		$("#div3 #div3-nav #btn-news").css("background-color","#ED1C24");
		$("#div3 #div3-nav #btn-blog").css("background-color","#666");
		return false;
	});
}); // end jQuery


/* 
*   Site Nav Animation Effect (jQuery)
*
*   jquery ready call
*   slide()
*
*/

/*
$(document).ready(function()
{
	slide("#nav-site", 25, 15, 150, .8);
});

function slide(navigation_id, pad_out, pad_in, time, multiplier)
{
	// creates the target path
	var link_elements = navigation_id + " li a";
	
	// initiates the timer used for the sliding animation
	var timer = 0;

	// creates the hover-slide effect for all link elements 		
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ paddingLeft: pad_out }, 100);
		},		
		function()
		{
			$(this).animate({ paddingLeft: pad_in }, 100);
		});
	});
}
*/

