/*--------------------------------------------------*
 *--------------------------------------------------*
 * rednoseday.com 2009 drupal theme                 *
 * Common javascript library                        *
 * Created by: CR New Media                         *
 *                                                  *
 * depends on jquery: www.jquery.com                *
 *--------------------------------------------------*
 *--------------------------------------------------*/

$(document).ready(function (){

  initTheme();
  gaSetup();
  
  if ($("#product_trailer")) $("#product_trailer").hide();
  if ($("#size_guide")) $("#size_guide").hide();
  
  $("form#post-code-search input#edit-postcode").focus(function() {
    if ($("form#post-code-search #edit-postcode").val() == 'Enter your postcode'){
      $("form#post-code-search #edit-postcode").val("");
    }
  });
  
  $("form#post-code-search #edit-postcode").blur(function() {
    if ($("form#post-code-search #edit-postcode").val() == ""){
      $("form#post-code-search #edit-postcode").val('Enter your postcode');
    }
  });
    
  $("#watchavideo").click(function(event) {
    $("#product_trailer").slideToggle();
    return false;
  });
    
  $("#product_trailer_close_button a").click(function(event) {
    $("#product_trailer").slideToggle();
    return false;
  });
    
  $("#sizeguide").click(function(event) {
    $("#size_guide").slideToggle();
    return false;
  });
    
  $("#product_size_guide_close_button a").click(function(event) {
    $("#size_guide").slideToggle();
    return false;
  });
  
  $("a[id^='product_tabbed_info_tab_']").click(function(event) {
    var selected = $(this).attr('name');
  
    $("div[id^='product_tabbed_info_copy_']").each(function(i){
    
      var current = this.id.charAt(25);
      
      if (current != selected){
        $("#product_tabbed_info_tab_"+current).removeClass('active');
        $("#product_tabbed_info_copy_"+current).hide();
      } else {
        $("#product_tabbed_info_tab_"+current).addClass('active');
        $("#product_tabbed_info_copy_"+current).show();
      }
    });
    
    return false;
  });
  
});
  
function initTheme(){
  
  // Add hasjavascript class to body
  $("body").addClass("hasjavascript");
  
  /* Using class toggle_div_next toggle open/close the subsequent element div
  **************************************************************************************************/
  $(".toggle_div_next").parent().next().toggle(); // Hide all on load
  $(".toggle_div_next").click(function() {
    $(this).parent().next().slideToggle("normal");
    return false;
  });
}

function fbs_click(node_title, full_blog_url)
{
  window.open('http://www.facebook.com/sharer.php?u=http://'+full_blog_url+'&amp;t='+node_title,'sharer','toolbar=0,status=0,width=626,height=436');
  return false;
}

function gaSetup(){
  $('.track_btn').click(function(){
		$tosend = '/' + $(this).attr('id').replace(/:/g, '/');
		pageTracker._trackPageview($tosend);
	});
}




