$(function(){
   $("body").addIDs();
   
   
   
   $(".payg .price").each(function(){
        var price = $("span",this).text();          
        var priceLength = price.substr(0,3);                
      $("span",this).text(priceLength);
      $(this).show();
    });
    
    $(".individual .price, .company .price").each(function(){
        var price = $("span",this).text();          
        var priceLength = price.substr(0,4);                
      $("span",this).text(priceLength);
      $(this).show();
    });
   
   $(".payg_options:first").addClass("payg_options_header");
   $(".payg_options").each(function(){
      $("h3:eq(0)",this).wrap("<div class='first'></div>");
      $("h3:eq(1)",this).wrap("<div class='second'></div>");
      $("h3:eq(2)",this).wrap("<div class='third'></div>");
      $("h3:eq(3)",this).wrap("<div class='fourth'></div>");
      $(".add_to_basket:last",this).attr("style","width: 111px;");
    });
   
    
    
    $(".area_of_law_options select").change(function(){   
        $(".payg_options .cat").each(function(){
            var Cat = $(this).text();         
            $(this).parent().parent().addClass(Cat);
        });   
        var thisCategory = $("option:selected",this).val();
		if (thisCategory!="null") {
			$(".payg_options").hide();
			$(".payg_options .cat:contains('"+thisCategory+"')").parent().parent().fadeIn();
			$(".payg_options_header").fadeIn();
		} else {
			$(".payg_options").hide();
			$(".payg_options, .payg_options_header").fadeIn();
		}
    }); 
    
    $(".li_one, .li_two, .li_three").each(function(){
        $("p:first",this).wrap("<div class='header'></div>");
    });
    
    $(".price_plan_item .desc").each(function(){
        
        $("li:eq(0)",this).addClass("first");
        $("li:eq(1)",this).addClass("second");
        $("li:eq(2)",this).addClass("third");
        
         
    });
    
    $(".individual .first").hover(function(){ $(".li_one, .li_two, .li_three").hide();      $(".individual .li_one").fadeIn();               },function(){      $(".individual .li_one").hide();    }); 
    $(".individual .second").hover(function(){ $(".li_one, .li_two, .li_three").hide();      $(".individual .li_two").fadeIn();               },function(){      $(".individual .li_two").hide();    }); 
    $(".individual .third").hover(function(){  $(".li_one, .li_two, .li_three").hide();     $(".individual .li_three").fadeIn();               },function(){      $(".individual .li_three").hide();    }); 
    
    $(".company .first").hover(function(){   $(".li_one, .li_two, .li_three").hide();    $(".company .li_one").fadeIn();               },function(){      $(".company .li_one").hide();    }); 
    $(".company .second").hover(function(){  $(".li_one, .li_two, .li_three").hide();     $(".company .li_two").fadeIn();               },function(){      $(".company .li_two").hide();    }); 
    $(".company .third").hover(function(){  $(".li_one, .li_two, .li_three").hide();     $(".company .li_three").fadeIn();               },function(){      $(".company .li_three").hide();    }); 
    
    $(".payg .first").hover(function(){  $(".li_one, .li_two, .li_three").hide();     $(".payg .li_one").fadeIn();               },function(){      $(".payg .li_one").hide();    }); 
    $(".payg .second").hover(function(){ $(".li_one, .li_two, .li_three").hide();      $(".payg .li_two").fadeIn();               },function(){      $(".payg .li_two").hide();    }); 
    $(".payg .third").hover(function(){  $(".li_one, .li_two, .li_three").hide();     $(".payg .li_three").fadeIn();               },function(){      $(".payg .li_three").hide();    }); 
    
    
    $(".payg").each(function(){
        $(".buy_now_btn",this).html("<a href='http://www.datalawonline.co.uk/plan-and-pricing/pay-as-you-go/default.phuse'></a>");
    });
    $(".pp_features:first h3").attr("style","width: 426px;");
    $(".pp_features ul li:last").attr("style","border: none;");
   
   
  // $(".mast_right").html("<img src='http://www.datalawonline.co.uk/res/builtin/mast_right_bg.jpg' />");      
   
  
   
   $(".course_links").hide();
   $("#navigation .NavigationMenu td:last a").css("border-right","0").css("padding-right","26px");
   
   $(".breadcrumb").each(function(){
        var charReplace = $(this).html();
        charReplace = charReplace.replace("&gt;","|");
        charReplace = charReplace.replace("&gt;","|");
        charReplace = charReplace.replace("&gt;","|");
        charReplace = charReplace.replace("&gt;","|");
       $(this).html(charReplace);
    });   
    
   $("#base .top ul").attr("style","margin-right: 20px;");
   $("#base .top ul:last").attr("style","margin-right: 0px;");
   
   
   $(".mm_form tr").each(function(){
        $("td:first",this).addClass("label");
        $("td:last",this).addClass("input");
    });
    $(".mm_form .label").wrapInner("<div></div>");
    $(".mm_form input:last").addClass("SubmitButton");
    $(".mm_form tr:last").addClass("SubmitButtonTR");
    $(".mm_form td:last").addClass("SubmitButtonTD");
    $(".mm_form .SubmitButtonTR td").removeClass("input");
    $(".mm_form .SubmitButtonTR .label").hide();
    $(".mm_form tr:first").addClass("first");
    
    $("#Header_3707").attr("href","http://www.datalawonline.co.uk");
    $(".course_link, .content_mid .news .item, .search_result_item").fullLink();
    $("#Header_3707").attr("href","http://www.datalawonline.co.uk");
    
    $(".course_link").each(function(){
        $(this).hover(function(){
           $(".course_links",this).show();
           $(".course_hover",this).attr("style","display: block;");
           
        },function(){
           $(".course_links",this).hide();
        });  
        $("li:nth-child(9)",this).addClass("no_border");
        $("li:nth-child(10)",this).addClass("no_border");
    });
    $(".links a:last").addClass("rss_link");
    
    $(".content_mid .news, .faqs").pagination({perPage:5});
    $(".faqs .faq:last").attr("style","border: 0;");
    
    if ($(".MMDataCaptureForm_ErrorTD span").text()!="") {
        $(".contact_form").attr("style","height: 278px;");           
    } else {
        $(".contact_form").attr("style","height: 266px;");          
    }
    
    
    $(".search_results .search_return .paging a").each(function(){
        var getStyle = $(this).attr("style");
        if (getStyle=="font-weight: bold; text-decoration: underline;") {
            $(this).css("text-decoration","none").css("background","#f2edf4").css("color","#000");
        }
    });
    
    if ($(".basket_item").is(":visible")) {
          
    }
    
    else {
        $(".basket_details, .basket_checkout").hide();   
        $(".basket_checkout").after("<div><p><strong>There are currently no items in this basket.</strong></p></div>");         
    }
    
    
    //$(".FieldListContainerCSS option:nth-child(2)").text("Firm \u00a3499");//
    $(".testimonial:eq("+Math.floor(Math.random()*$(".testimonials .testimonial").length)+")").show();
    
    $(".FieldListContainerCSS option").each(function(){
		var originalString = $(this).text();
		var cutOffPosition = originalString.indexOf("(");
		var newString = originalString.substr(0,Math.floor(cutOffPosition-1));
		if (cutOffPosition>0) {
			$(this).text(newString);
		}
    });
    
    $(".testimonial_panel").each(function(){
        $("p:first strong:first",this).before("<img src='http://staging.ph-creative.com/sites/datalaw/res/builtin/open_quote.gif' style='margin-right:10px;'>");
        $("p:first strong:last",this).after("<img src='http://staging.ph-creative.com/sites/datalaw/res/builtin/close_quote.gif'  style='float:right;'>");
        //$("p:last",this).hide();
        //var TestimonialName = $("p:last",this).html();
        //$(".name",this).html(TestimonialName);
    });
    
    $("#calculate_btn").live("click",function(){
    
		var seminarHours = eval($("#seminarHours").val()*1);
		var seminarHoursTravelling = eval($("#seminarHoursTravelling").val()*1);
		var inHouseHours = eval($("#inHouseHours").val()*1);
		var inHouseHoursTravelling = eval($("#inHouseHoursTravelling").val()*1);
		var formHourlyRate = eval($("#formHourlyRate").val()*1);
		var onlineHours = eval($("#online_hours").val()*1);

        if($('#onlineBillableYes').attr('checked')===true) { 
            
		    var Hours = seminarHours+seminarHoursTravelling+inHouseHours+inHouseHoursTravelling+onlineHours;
            
        }
        
        if($('#onlineBillableNo').attr('checked')===true) { 
            var Hours = seminarHours+seminarHoursTravelling+inHouseHours+inHouseHoursTravelling;
        }

        var Total = formHourlyRate*Hours;
		$("#result").text(Total).show();
		$("#result").wrapInner("<span>\u00a3</span>");
		$("#result span").before("<div>Each year, doing your CPD during your billable hours costs you: </div>");

		return false;
	});
	$("#lostHoursForm fieldset:last").attr("style","");

    
    var urlsubnav = window.location;
    $(".sub_nav .news .item a[href$="+urlsubnav+"]").parent().addClass("active");
    
    
    
    
});

