$(document).ready(function(){

    putTeasersInSideBar();
    openSpecificClient();
    addHomePageListeners();
    setupSlideShow();
    catMenu();

    $strHTML = "<div class=\"logo-image\"><p>Copyright 2008 CGLawyers. Web Design by <a href=\"http://www.vicwebster.net\">Vic Webster</a></p></div>";
    $("#prev-clients li.client-li").prepend($strHTML);
    $("#prev-clients li#default div.logo-image").remove();

    $("div.scrollable").scrollable({ 
        size:6
    }).circular();

    $("ul.items li a").click( function(e) {

        e.preventDefault();
        $(this).parent().click();

        divID = "#"+$(this).parent().attr("id")+"-div";

        $("#prev-clients .active").hide("normal", function() {

            $(this).removeClass("active");
            $(divID).show("normal");
            $(divID).addClass("active");     

        });

    });

/*
    $("ul#nav a").mouseover(
        function(e){
            $specialID = "arrow-"+$(this).parent().attr("class");
            $(this).parent().append("<span id=\""+$specialID+"\" class=\"arrow hidden\"> (click to continue) </span>");
            $("#"+$specialID).show("quick");

        });

    $("ul#nav a").mouseout(
        function(e) {
            $specialID = "#arrow-"+$(this).parent().attr("class");
            $($specialID).remove();
        //$($specialID).fadeOut( "quick", function (e) { $($specialID).remove() } );
        });

*/
    $("#searchTypeLogo").click(
        function (e) {
            $("#phraseField").hide("normal", function(){
                $("#imageField").show("normal");
            });
        }
        );
           
	
    $("#searchTypeWord").click(
        function (e) {
            $("#imageField").hide("normal", function(){
                $("#phraseField").show("normal");
            });
        }
        );


    if ( $("#searchTypeWord:checked").val() == "phrase" )
    {
        $("#phraseField").show("normal");
    }
    else if ( $("#searchTypeLogo:checked").val() == "logo" )
    {
        $("#imageField").show("normal");
    }


});



function putTeasersInSideBar() {

    $teaserElement = $(".teaser");
    $teaserElement.insertBefore("#fred");
    $teaserElement.addClass("innerBox");
	
}


function openSpecificClient() {

    var divID = "#" + querySt("client") + "-div";
 
    if ($(divID).html() != null) {

        $("#prev-clients .active").hide("normal", function() {

            $(this).removeClass("active");
            $(divID).show("normal");
            $(divID).addClass("active");

        });
    }
}


function querySt(ji) {

    hu = window.location.search.substring(1);
    gy = hu.split("&");

    for (i=0;i<gy.length;i++) {

        ft = gy[i].split("=");

        if (ft[0] == ji) {
            return ft[1];
        }

    }
}


function addHomePageListeners() {

    var moreLink = "<a href=\"#\" class=\"moreLink\">...tell me more!</a>";
    $("h3.moreComing").after(moreLink);
	
    $(".moreLink").click( function (e) {
	
        e.preventDefault();
        var articleId = "#"+$(this).parent().attr("id");
		
		
        if ( $("#main .active").html() != null ) {
		
            $("#main .active").hide("slow", function (e) {
				
                $(this).parent().find(".moreLink").fadeIn ("slow");
                $("#main .active").removeClass("active");
                $(articleId + " .more").show("slow");
                $(articleId + " .more").addClass("active");
                $(articleId + " .moreLink").fadeOut("slow");
		
            });
		
        } else {
			
            $(articleId + " .more").show("slow");
            $(articleId + " .more").addClass("active");
            $(articleId + " .moreLink").fadeOut("slow");
		
        }
		
			
	
    });

}


function setupSlideShow() {

    $('#gallery a').lightBox({
        size:7
    });
}



function catMenu()
{
    var button = $("a#blCat");
    var catMenu = $("div#blogCategories");
    var slideUpAreas = $("a#blHome, a#blRec, a#blWeb, div#main, div#header, ul#nav");
    var xPos = button.offset().left;
    var yPos = button.offset().top + 90;
    catMenu.css("left", xPos+"px");
    catMenu.css("top", yPos+"px");

    button.click( function(e) {

       e.preventDefault();
       catMenu.slideDown("fast");

    });

    slideUpAreas.mouseenter ( function(e) {
        catMenu.fadeOut("slow");
    });

}





