$(function() {
    
    $(".footer_icon:last").css("margin-right","0px");
    
    // Marketing Manager Form    
    $(".mm table").addClass("MMDataCaptureForm_Table");    
    $(".MMDataCaptureForm_Table tr").each(function(){
        $("td:first",this).addClass("MMDataCaptureForm_LabelTD");
        $("td:last",this).addClass("MMDataCaptureForm_FieldTD");
    });    
    
    $(".MMDataCaptureForm_Table").each(function(){
        $(".MMDataCaptureForm_FieldTD input",this).addClass("MMDataCaptureForm_Input");        
        $(".MMDataCaptureForm_LabelTD:last",this).addClass("MMDataCaptureForm_ButtonEmptyTD").removeClass("MMDataCaptureForm_LabelTD");
        $(".MMDataCaptureForm_FieldTD:last",this).addClass("MMDataCaptureForm_ButtonTD").removeClass("MMDataCaptureForm_FieldTD");        
        $(".MMDataCaptureForm_ButtonTD input",this).addClass("MMDataCaptureForm_SubmitButton").removeClass("MMDataCaptureForm_Input");
    });  
       
    $(".MMDataCaptureForm_Table tr").each(function(){
        var labelText = $(".MMDataCaptureForm_LabelTD",this).text();
        $(".MMDataCaptureForm_Input",this).val(labelText);
    });	
	$(".MMDataCaptureForm_Input").each(function(){
		var thisObj=$(this);
		var thisVal=thisObj.val();
		thisObj.bind("focus",function(){
			if (thisObj.val()==thisVal) { thisObj.val(""); }
		}).bind("blur",function(){
			if (thisObj.val()=="") { thisObj.val(thisVal); }
		});
	});
	
	
	
    
    var COOKIE_NAME = 'lightswitch';

    if ($.cookie(COOKIE_NAME)=="on") {
         $(".switchon").hide();
         $(".switchoff").show();
         $("#CSS_7").removeAttr("href");
         $(".footer_icon, .ph_logo, .phuse_logo, .accreditations, .contact_form .MMDataCaptureForm_Table, .map, .img_padding_left, .img_padding_right").css("opacity","1");
         $(".day").show();
         $(".night").hide();

    } else if ($.cookie(COOKIE_NAME)=="off") {
         $(".switchon").show();
         $(".switchoff").hide();
         $("#CSS_7").attr("href","http://www.eco-environments.co.uk/res/css/Dark.css");
         $(".footer_icon, .ph_logo, .phuse_logo, .accreditations, .contact_form .MMDataCaptureForm_Table, .map, .img_padding_left, .img_padding_right").css("opacity","0.2");
         $(".day").hide();
         $(".night").show();
    }
    
    $(".MMDataCaptureForm_ErrorTD span").attr("style","");
 
    $(".paging a").each(function(){
        var getStyle = $(this).attr("style");
        if (getStyle=="font-weight: bold; text-decoration: underline;") {
            $(this).css("text-decoration","none");
        }
    });
    
    $(".paging a").each(function(){
        $(this).html($(this).html().replace("Next &gt;","&gt;").replace("&lt; Prev","&lt;"));
    });

    
    var blogContent = $(".blogFeed").html();
    $("#blogFeed").html(blogContent);
    $("#blogFeed li:nth-child(1)").addClass("first_blog");
    $("#blogFeed li:last").css("border","none");

    $(".popup").hide();
    $(".footer_icon").hover(function(){
        $(this).parent().children(".popup").fadeIn("fast");
    },function(){
        $(this).parent().children(".popup").hide();
    });
    
    var urltopnav = window.location;
    $(".top_nav a[href$="+urltopnav+"]").parent().addClass("active_tab");
    
    $(".NavigationMenu td:nth-child(1) .divide").hide();
    $(".NavigationMenu td:nth-child(1)").css("background","none");
    
    $("textarea").attr("style","");
   
    
    
    if (($.browser.ie6)) {
        $(".footer_mid").css("margin","19px 0 1px 0px");
        $(".divide").css("display","none");
    }
    
    $(".switchoff").click(function(){
    $.cookie(COOKIE_NAME, 'off', { path: '/', expires: 1 });
        $(".switchon").show();
         $(".switchoff").hide();
         $("#CSS_7").attr("href","http://www.eco-environments.co.uk/res/css/Dark.css");
         $(".footer_icon, .ph_logo, .phuse_logo, .accreditations, .contact_form .MMDataCaptureForm_Table, .map, .img_padding_left, .img_padding_right").css("opacity","0.2");
         $(".day").hide();
         $(".night").show();
    });
    
    $(".switchon").click(function(){
    $.cookie(COOKIE_NAME, 'on', { path: '/', expires: 1 });
        $(".switchon").hide();
         $(".switchoff").show();
         $("#CSS_7").removeAttr("href");
         $(".footer_icon, .ph_logo, .phuse_logo, .accreditations, .contact_form .MMDataCaptureForm_Table, .map, .img_padding_left, .img_padding_right").css("opacity","1");
         $(".day").show();
         $(".night").hide();
    });

    if ($(".login_panel").is(":visible")) {
        $("html, body").animate({ scrollTop: 250}, "slow");
    }
    
    if ($(".indent").is(":visible")) {
        $("blockquote",this).attr("style","");
        $("blockquote",this).wrap("<div class='blockquote'></div>");
        $("blockquote",this).before("<div class='block_top'></div>");
        $("blockquote",this).after("<div class='block_btm'></div>");
        
         $(".curved_img").parent().parent().parent().parent().attr("width","342px;").attr("style","float: left; margin-right: 19px;");
         $(".curved_img").parent().addClass("jim").attr("style","float: left; margin-right: 19px; width: 342px;");
    }

    /* $(document).mousemove(function(e) {
        if ($(".switchoff").is(":visible")) {
            mouseX = e.pageX;
            mouseY = e.pageY;
            if ((mouseX > eval($(document).width()-10000))&&(mouseY < 15)) {
                $(".warning").fadeIn();
            } else {
                $(".warning").fadeOut();
            }
        }
    }); */
    
        if ($(".gallery").is(":visible")) {
            $(".gallery img").each(function(){
                var imgUrl = $(this).attr("src"); 
                $(this).wrap("<a href='"+imgUrl+"'></a>"); 
                $(this).parent().lightBox(); 
            });
            
            var pagingItems1 = Math.ceil(eval($(".gallery .photo").length-12)/12);
            var countItems = 1;
           
            while (countItems<=pagingItems1+1) {
                $(".paging").append("<span id=\""+countItems+"\">"+countItems+"</span>");
                countItems++;
            }
            $(".paging span:first").addClass("active");
            $(".paging span").click(function(){
                $(".paging span").removeClass("active");
                $(this).addClass("active");
                var pageNumber=$(this).attr("id")-1;
                $(".gallery .photo").animate({"top":"-"+eval(pageNumber*348)+"px"});

            });
        }
        
  var pagingItems1 = Math.ceil(eval($(".news_item").length-8)/8);
            var countItems = 1;
           
            while (countItems<=pagingItems1+1) {
                $(".paging").append("<span id=\""+countItems+"\">"+countItems+"</span>");
                countItems++;
            }
            $(".paging span:first").addClass("active");
            $(".paging span").click(function(){
                $(".paging span").removeClass("active");
                $(this).addClass("active");
                var pageNumber=$(this).attr("id")-1;
                $(".news_item").animate({"top":"-"+eval(pageNumber*640)+"px"});

            });
    
});

function CheckMultiple100(frm, name) {
    for (var i=0; i < frm.length; i++) {
        fldObj = frm.elements[i];
        fldId = fldObj.id;
        if (fldId) {
            var fieldnamecheck=fldObj.id.indexOf(name);
            if (fieldnamecheck != -1) {
                if (fldObj.checked) {
                    return true;
                }
            }
        }
    }
    return false;
}
function CheckForm100(f) {
    var email_re = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
    if (!email_re.test(f.email.value)) {
        alert("Please enter your email address.");
        f.email.focus();
        return false;
    }
    return true;
}
