function getBody(function_full) {    
 // Get content between first { and last }  
 if (function_full && (function_full.search("function") != "-1")) {
  var m = function_full.toString().match(/\{([\s\S]*)\}/m)[1];   
  // Strip comments
  m.replace(" ",'');
  return m.replace(/^\s*\/\/.*$/mg,'');
 } else {
   return function_full;
 } 
} 

function redraw_buttons() { 
 $("#content img").each(function() {  
  if (($(this).attr("src").search("button") != "-1") && ($(this).css("display") != "none")) {
   $(this).parent().addClass("tn");
   $(this).parent().append("<em class=\"replaced_button\" title=\""+$(this).attr("title")+"\">"+$(this).attr("title")+"</em>");
   $(this).hide();
  }  
 });
 
 $(".inpopup img").each(function() {  
  if (($(this).attr("src").search("button") != "-1") && ($(this).css("display") != "none")) {
   $(this).parent().addClass("tn");
   $(this).parent().append("<em class=\"replaced_button\" title=\""+$(this).attr("title")+"\">"+$(this).attr("title")+"</em>");
   $(this).hide();
  }  
 });  
 
 $("#content form").each(function() {    
  content_form = $(this);  
  content_form.find("input[type=image]").each(function() {
   if (($(this).attr("src").search("button") != "-1") && ($(this).css("display") != "none")) {    
    onclick_event = getBody($(this).attr("onclick"));
    if (onclick_event) {
     $(this).parent().append("<em class=\"replaced_button\" title=\""+$(this).attr("title")+"\" onclick=\""+onclick_event+"\">"+$(this).attr("title")+"</em>");
    } else{
       var attr = content_form.attr('onsubmit');
       form_method = (typeof attr !== 'undefined' && attr !== false && attr !== null) ? 'onsubmit' : 'submit';
       $(this).parent().append("<em class=\"replaced_button\" title=\""+$(this).attr("title")+"\" onclick=\"document."+content_form.attr("name")+"."+form_method+"();\">"+$(this).attr("title")+"</em>");       
      } 
    $(this).hide();
   }     
  });
 });
 
 $(".inpopup form").each(function() {
  content_form_1 = $(this);  
  content_form_1.find("input[type=image]").each(function() {
   if (($(this).attr("src").search("button") != "-1") && ($(this).css("display") != "none")) {
    onclick_event = getBody($(this).attr("onclick"));    
    if (onclick_event) {
     $(this).parent().append("<em class=\"replaced_button\" title=\""+$(this).attr("title")+"\" onclick=\""+onclick_event+"\">"+$(this).attr("title")+"</em>");
    } else {
       var attr = content_form_1.attr('onsubmit');
       form_method = (typeof attr !== 'undefined' && attr !== false && attr !== null) ? 'onsubmit' : 'submit';
       $(this).parent().append("<em class=\"replaced_button\" title=\""+$(this).attr("title")+"\" onclick=\"document."+content_form_1.attr("name")+"."+form_method+"();\">"+$(this).attr("title")+"</em>");
      } 
    $(this).hide();
   }     
  });
 }); 
 
 $(".customization form").each(function() {    
  content_form_2 = $(this);  
  content_form_2.find("input[type=image]").each(function() {
   if (($(this).attr("src").search("button") != "-1") && ($(this).css("display") != "none")) {
    onclick_event = getBody($(this).attr("onclick"));
    if (onclick_event) {
     $(this).parent().append("<em class=\"replaced_button\" title=\""+$(this).attr("title")+"\" onclick=\""+onclick_event+"\">"+$(this).attr("title")+"</em>");
    } else {
       var attr = content_form_2.attr('onsubmit');
       form_method = (typeof attr !== 'undefined' && attr !== false && attr !== null) ? 'onsubmit' : 'submit';
       $(this).parent().append("<em class=\"replaced_button\" title=\""+$(this).attr("title")+"\" onclick=\"document."+content_form_2.attr("name")+"."+form_method+"();\">"+$(this).attr("title")+"</em>");
      }
    $(this).hide();
   }  
 });
});
}

function clean_value(element, value, is_clear) {if (element.attr("value") == value || element.attr("value") == "") {if (is_clear) {element.attr("value", "");};element.addClass("viewable");}}
function restore_value(element, value, is_clear) {if (element.attr("value") == "" || element.attr("value") == value) {if (is_clear) {element.attr("value", value);}; element.removeClass("viewable");}}
function lightRows(parent_class, row_element){var g=document.getElementsByTagName("*"),a,b,f=g.length,e=new RegExp("(^|\\b)"+parent_class+"(\\b|$)");while(f--){if(e.test(g[f].className)){a=g[f].getElementsByTagName(row_element);for(b=0;b<a.length;b=b+2){a[b].className="colored"}}}};

var formfields_counter = 0;
var start_values = new Array;

function dispatch_values(field_class, is_clear) { 
 pieces = field_class.split(" ");
 field_class_out = pieces[pieces.length-1]; 
 prefix = field_class.split(field_class_out)[0];
 field_class= field_class_out; 
 
 $(prefix+"input"+field_class).each(function() {
  $(this).attr("rel", field_class.split(".")[1]+formfields_counter);
  start_values[formfields_counter] = $(this).attr("value");   
  formfields_counter++;
 });  

 $(prefix+"input"+field_class).focus(function() {    
     clean_value($(this), start_values[$(this).attr("rel").split(field_class.split(".")[1])[1]], is_clear);  
 });
 
 $(prefix+"input"+field_class).blur(function() {  
  restore_value($(this), start_values[$(this).attr("rel").split(field_class.split(".")[1])[1]], is_clear);
 });
}

function tabs(tabs, tab, switcher) { 
 $(tab).hide(); //Hide all content
 $(switcher+":first-child").addClass("active").show(); //Activate first tab
 $(tab+":first-child").show(); //Show first tab content

  //On Click Event
 $(switcher).click(function() { 
  $(switcher).removeClass("active"); //Remove any "active" class
  $(this).addClass("active"); //Add "active" class to selected tab
  $(tab).hide(); //Hide all tab content
  var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
  $(activeTab).fadeIn(); //Fade in the active content
  return false;
 });
}

function slider_initialize(tab, slider_wrap, slider_, width, expand_, resizeContents_, delay_) {
 if (tab != "") {
  $(tab).each(function() {    
   var slider_wrap_ = "#"+$(this).attr("id")+" "+slider_wrap;
   var slider__ = "#"+$(this).attr("id")+" "+slider_;  
   slider_create(slider_wrap_, slider__, width, expand_, resizeContents_, delay_);  
  })
 } else {
    slider_create(slider_wrap, slider_, width, expand_, resizeContents_, delay_);  
 }
}

function redraw_submits(wrap_class) {
 $(wrap_class+" input").each(function() {  
  $(this).attr("value", $(this).attr("title"));
  $(this).removeAttr("title");
  $(this).removeAttr("alt");  
  $(this).removeAttr("src");
  $(this).parent().html($(this).parent().html().replace("image", "submit"));
 });
}

var show_ad = false;
function show_hide_ad() {
 var scr_width = $("body").width(); 
 if (show_ad) {
  if (scr_width <= 1170) {   
   $("body").removeClass("with_gad");
  } else {
     $("body").addClass("with_gad");
  }
 } 
}

function start_scroll() {  
 if ((parseInt($("#span_search_string .marquee div").width())) > $("#span_search_string .marquee").width()) {
  scroll_string_left();
 } else {
    stop_scroll();
 }
}

function stop_scroll() {
 $("#span_search_string .marquee div").stop();
 $("#span_search_string .marquee div").css("left", "0"); 
}

function scroll_string_left () {
  $("#span_search_string .marquee div").animate({"left": "-=1px"}, {
    duration: 30,
    complete: function() {           
     if (parseInt($(this).width() + parseInt($(this).css("left"))) >= parseInt(parseInt($("#span_search_string .marquee").width()))) {
      scroll_string_left()
     } else {
        scroll_string_right()
     };
    }
   } 
  );
}
 
function scroll_string_right () {
 $("#span_search_string .marquee div").animate({"left": "+=1px"}, {
    duration: 30,
    complete: function() {
     if (parseInt($(this).css("left")) == 0) {
      scroll_string_left()
     } else {
        scroll_string_right()
      };
    }
   } 
  );
}

function getBodyScrollTop() {  
 return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);  
}  

jQuery(function($){
/* $(".login_link").click(function() {
  $(".login_form").addClass("viewable");
  return false;
 });*/
 
 $("#clear_string").click(function(){
  $("#voice_search_txt").attr("value", "");
  $(this).removeClass("filled");
  $("#span_search_string .marquee").html("");
 })
 
 if ($("#voice_search_txt").attr("value")) {$("#clear_string").addClass("filled")};
 
 $("#voice_search_txt").keyup(function(){
  if (!$("#clear_string").hasClass("filled") && ($(this).attr("value") != "")) {
   $("#clear_string").addClass("filled")
  }   
  if ($(this).attr("value") == "") {
   $("#clear_string").removeClass("filled")
  }
 })
 
 $(window).resize(function() {   
  show_hide_ad();
  stop_scroll();
  start_scroll();  
 });
 
 dispatch_values(".search .formfields", true);
 dispatch_values(".search_form .formfields", false);  
 
 redraw_submits("#top .login_form .button");
 redraw_buttons(); 
 start_scroll();
 show_hide_ad();
 
 $(".row_description .more").click(function() {
  $(this).toggleClass("less").prev().toggleClass("view");
  return false;
 }); 
 
 $(".plans input[type=radio]").each(function() {
   if ($(this).attr("checked") == "checked") {
    $(this).parent().addClass("active");
   }
 });
 
 $(".plans li").click(function() {
  $(this).parent().parent().find("li").removeClass("active");
  $(this).addClass("active");
  $(this).parent().parent().find("input[type=radio]").removeAttr("checked");
  $(this).find("input[type=radio]").attr("checked", "checked");
 }); 
 
 if($("body").find(".detail_name").html()) {
  $("body").addClass("narrow");
 }
 
 $(".detail_links a").click(function(){
  $(".detail_links a").each(function(){
   $(this).removeClass("active");
  })
  $(this).addClass("active");
 }) 
 
 $(window).scroll(function(){  
  scrolled = getBodyScrollTop();
  if ($("body").hasClass("narrow")) {
   check_value = 176
  } else {
     check_value = 223
  }
  
  if (scrolled > check_value) {
   $(".member_menu_wrap").addClass("first-plan")
  } else {
     $(".member_menu_wrap").removeClass("first-plan")
    }
 })
 
 if ($("body").find("#partner_top").html()) {
  $(".gad").css("top", $("body").find("#partner_top").height()+15+"px");
 }
 
});
