$(document).ready(function () {

    // parse url on load to do something 
    /*var qString = document.location.href;
    qString = qString.split('?')[1];
    if (qString !== "") {
    doSomething()
    }
    */

    $('header ul ul').mouseenter(function () {
        $(this).prev('a').addClass('over');
    });
    $('header ul ul').mouseleave(function () {
        $(this).prev('a').removeClass('over');
    });

    fkpSubNav.init();
    $(window).resize(function () {
        fkpSubNav.init();
    });

    $('.builder_row').equalHeights();
    $(".builders .builder .lot").mouseover(function (evt) {
        // console.log($(this).parent().find("img"));
        var imgPath = $(this).attr("rel");
        $(this).parent().find("img").attr('src', imgPath);
        //console.log($(this).attr("rel"));
    });

   
    // adds an effect called "myEffect" to tabs
    $.tools.tabs.addEffect("myFade", function (tabIndex, done) {

        // hide all panes and show the one that is clicked
        this.getPanes().fadeOut().eq(tabIndex).fadeIn(2000);

        // the supplied callback must be called after the effect has finished its job
        done.call();
    });
    // setup ul.tabs to work as tabs for each div directly under div.panes
    $("ul.tabs").tabs("div.panes > div", {
        effect: 'myFade'
    });
    // setup scrollable
    $(".scrollable").scrollable();
    $('.scrollable .items a').click(function (evt) {
        evt.preventDefault();
        var pane = $('.panes > div:visible');
        pane.addClass('.loading');
        var src = $(this).attr('href');
        var img = new Image();
        $(img)
					.load(function () {
					    $(this).hide();
					    // with the holding div, apply:
					    pane
					    // remove the loading class (so no background spinner), 
							.removeClass('loading')
					    // then insert our image
							.append(this);

					    // fade our image in to create a nice effect
					    $(pane).children('img').hide();
					    $(this).fadeIn();
					})

        // if there was an error loading the image, react accordingly
					.error(function () {
					    // notify the user that the image could not be loaded
					})

        // *finally*, set the src attribute of the new image to our image
					.attr('src', src);
    });


});

var fkpSubNav = {
	wrap: $('.wrap'),
	nav: $('.nav'),
	init: function () {
		var navWd = parseInt(this.wrap.width());
		var offset = parseInt(this.nav.offset().left);
		var lt = 0;
		var paddLt = 0;
		if (navWd > 1390) { 
			navWd = 1174;
			lt = -215;
			paddLt = 215;
		} else {
			lt = -offset;
			paddLt = Math.abs(lt); 
			navWd = navWd - paddLt;
		}
		$('ul.nav ul').css({
			width: navWd,
			left: lt,
			paddingLeft: paddLt
		});
	}
};


