$(function(){
	var bgColor=new Array();
        bgColor[0]="http://www.gillingdod.com/res/builtin/bg0.jpg";
        bgColor[1]="http://www.gillingdod.com/res/builtin/bg1.jpg";
        bgColor[2]="http://www.gillingdod.com/res/builtin/bg2.jpg";
        bgColor[3]="http://www.gillingdod.com/res/builtin/bg3.jpg";
        bgColor[4]="http://www.gillingdod.com/res/builtin/bg4.jpg";
        bgColor[5]="http://www.gillingdod.com/res/builtin/bg5.jpg";
        bgColor[6]="http://www.gillingdod.com/res/builtin/bg6.jpg";
        bgColor[7]="http://www.gillingdod.com/res/builtin/bg7.jpg";
        bgColor[8]="http://www.gillingdod.com/res/builtin/bg8.jpg";
        bgColor[8]="http://www.gillingdod.com/res/builtin/bg9.jpg";
    var randomColor=Math.floor(Math.random()*9);
    $("body").attr("style","background: #080808 url("+bgColor[randomColor]+") no-repeat top left fixed;");
	
	$(".NavigationMenu td:first").attr("style","padding-left: 9px;");
	$("#breadcrumb").each(function(){
        var charReplace = $(this).html();
        charReplace = charReplace.replace("&gt;","&nbsp;/&nbsp;");
        charReplace = charReplace.replace("&gt;","&nbsp;/&nbsp;");
        charReplace = charReplace.replace("&gt;","&nbsp;/&nbsp;");
        charReplace = charReplace.replace("&gt;","&nbsp;/&nbsp;");
        $(this).html(charReplace);
    });
    
    $(".Phuse_Breadcrumb_Link, .Phuse_Breadcrumb_CurrentPage_Header_Link").each(function(){
        var Phuse_Breadcrumb_Link = $(this).text();
        
        if ($(this).text()=="Healthcare") {
            $("#content").addClass("healthcare");
        }
        if ($(this).text()=="Education") {
            $("#content").addClass("education");
        }
        if ($(this).text()=="Commercial / Industrial") {
            $("#content").addClass("commercial");
        }
        if ($(this).text()=="Commercial") {
            $("#content").addClass("commercial");
        }
        if ($(this).text()=="Residential") {
            $("#content").addClass("residential");
        }
        if ($(this).text()=="Interior Design") {
            $("#content").addClass("interior");
        }
        if ($(this).text()=="Other Markets") {
            $("#content").addClass("markets");
        }       
    });
    
    if ($(".case_studies:visible")) {
        $(".case_studies .case").each(function(){
            var caseCategory = $(".cat",this).text();
           
                 
            if ($(".Phuse_Breadcrumb_CurrentPage_Header_Link").text()==caseCategory) {
                $(this).show();
            }
            
            if ($(".Phuse_Breadcrumb_Link:last").text()==caseCategory) {
                $(this).show();
            } 
            
            if ($(".Phuse_Breadcrumb_Link:last").text()=="Commercial") {
                $(this).show();
            }
        });
        
        $(".view_more").click(function(){
           $(".case").show();
           $("a",this).removeAttr("href").hide();
        });
    } 
    
    
	$(".people_feed .people:last, .services_feed .service:last, .new_services_feed .service:last, .history_item:last").attr("style","border: none; margin-bottom: 0;"); 
    
    $(".sector_feed .sector:nth-child(1)").addClass("one");
    $(".sector_feed .sector:nth-child(2)").addClass("two");
    $(".sector_feed .sector:nth-child(3)").addClass("three");
    $(".sector_feed .sector:nth-child(4)").addClass("four");
    $(".sector_feed .sector:nth-child(5)").addClass("five");
    $(".sector_feed .sector:nth-child(6)").addClass("six");
       
    $(".call").each(function(){
	    $("p:first",this).addClass("first");
	    $("p:last",this).addClass("last");
	});
	
	$(".quote").each(function(){
	    $("p:last",this).addClass("name");
	});
	
	$(".gallery_item:nth-child(3n+3)").attr("style","margin-right: 0;"); 	
	$(".case_studies .case, .media .project, .media .news, .sector").fullLink();
	
	var pagingItems1 = Math.ceil(eval($(".main_news_feed .main_news").length-5)/5);
    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;
        $(".main_news_feed .main_news").animate({"top":"-"+eval(pageNumber*730)+"px"});
    }); 
    
    //var galleryItems1 = Math.ceil(eval($(".gallery_feed .gallery_item").length-5)/5);
    //var countItems = 1;   
    //while (countItems<=galleryItems1+1) {
        //$(".gallery_feed .paging").append("<span id=\""+countItems+"\">"+countItems+"</span>");
        //countItems++;
    //}
    //$(".gallery_feed .paging span:first").addClass("active");
    //$(".gallery_feed .paging span").click(function(){
        //$(".paging span").removeClass("active");
        //$(this).addClass("active");
        //var pageNumber=$(this).attr("id")-1;
        //$(".gallery_item").animate({"top":"-"+eval(pageNumber*330)+"px"});

    //}); 
    $(".gallery_feed #paging").hide();
    
    $(".news_feed .date").each(function(){
        var origText=$(this).text();
        var splitText=origText.split("");
        $(this).html("<span class='format'><span class='day'>"+splitText[0]+ +splitText[1]+ "</span><span class='month'>"+splitText[3]+ +splitText[4]+"</span></span>");
     });
    
    $(".format .month").each(function(){
        var date=$(this).text();
        if ($(this).text()=="01") {$(this).html("Jan");}
        if ($(this).text()=="02") {$(this).html("Feb");} 
        if ($(this).text()=="03") {$(this).html("Mar");} 
        if ($(this).text()=="04") {$(this).html("Apr");} 
        if ($(this).text()=="05") {$(this).html("May");} 
        if ($(this).text()=="06") {$(this).html("Jun");} 
        if ($(this).text()=="07") {$(this).html("Jul");}
        if ($(this).text()=="08") {$(this).html("Aug");} 
        if ($(this).text()=="09") {$(this).html("Sep");} 
        if ($(this).text()=="10") {$(this).html("Oct");} 
        if ($(this).text()=="11") {$(this).html("Nov");} 
        if ($(this).text()=="12") {$(this).html("Dec");} 
    });
    
    $(".mm_form tr").each(function(){
        $("td:first",this).addClass("label");
        $("td:last",this).addClass("input");
    });
    
    $(".mm_form .label").wrapInner("<div></div>");
    $(".mm_form tr textarea").parent().addClass("textarea");
    
    $(".mm_form").each(function(){
        $("input:last",this).addClass("SubmitButton");
        $(".label:last",this).hide();
        $("tr:last",this).addClass("SubmitButtonTR");
        $("td:last",this).addClass("SubmitButtonTD");
        $(".SubmitButtonTD",this).removeClass("input");
        $("textarea",this).parent().removeClass("input");
        $("textarea",this).parent().addClass("textarea");
        $("form",this).addClass("form");
        $(".textarea",this).prev().addClass("textarea_label");
        $(".textarea_label",this).removeClass("label");
    });  
    
    $(".right .mm_form tr, .content_right .mm_form tr").each(function(){
        var labelText = $(".label",this).text();
        var labelTextArea = $(".textarea_label",this).text();
        $(".input input",this).val(labelText);
        $(".textarea textarea",this).val(labelTextArea);
    });
	
	$(".input input, .textarea textarea").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); }
		});
	}); 
	
	$(".search_results_pane .paging_filter a").each(function(){
        $(this).wrap("<span></span>");
        var getStyle = $(this).attr("style");
        if (getStyle=="font-weight: bold; text-decoration: underline;") {
            $(this).css("text-decoration","none").css("font-weight","normal").parent().addClass("active");
        }        
    });
    
    var categorylist = $(".categorylist").html();
        $("#category_list").html(categorylist);
        
    $("#searchbox label").show().wrap("<h4></h4>");
    
    $(".inline_flow_right, .inline_flow_left").parent().attr("style","");

    
        
});
