$(document).ready(function () {
    $(".input, textarea").bind("focusin", function() {
        if ($(this).val() == $(this).attr("data-default")) { $(this).val(""); }
    });
    $(".input, textarea").bind("focusout", function() {
        if ($(this).val() == "") { $(this).val($(this).attr("data-default")); }
    });
    $(".password-clear").css("display", "block");
    $(".password").css("display", "none");
    $(".password-clear").bind("focusin", function() {
        $(this).css("display", "none");
        $(this).parent("p").children(".password").css("display", "block").focus();
    });
    $(".password").bind("focusout", function() {
        if ($(this).val() == "")
		{
            $(this).css("display", "none");
            $(this).parent("p").children(".password-clear").css("display", "block");
        }
    });
    $("form#contact-form .json").val("1");
    $("form#contact-form").submit(function () {
        var j = $(this),
            f = j.find("input, textarea").not(':submit, :checkbox, :radio, [type="hidden"]'),
            c = j.find(".req"),
            d = j.find(".message"),
            g = "You did not complete all of the fields. Please try agian.",
            k = j.find("input.email"),
            i = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        e = 0;
        c.removeClass("error");
        c.each(function () {
            if ($(this).val() == "" || $(this).val() == $(this).attr("data-default"))
			{
                e=1;
                $(this).addClass("error").css({ "border-color": "#7d7d7d" });
            }
        });
        d.hide().removeClass("error success");
        if (e == 1) { d.addClass("error").html(g).show(); }
		else
		{
            if (i.test(k.val()) == false)
			{
                k.addClass("error");
                d.addClass("error").html("Please provide a valid email address.").show()
            }
			else
			{
                var h = j.serialize();
                h = h + "&" + j.find('[type="submit"]').attr("name") + "=1";
                $.ajax({
                    url: j.attr("action"),
                    data: h,
                    type: "post",
                    dataType: "json",
                    success: function(l)
					{
                        if(l.error != undefined && l.error == "1") { d.addClass("error").html(l.message).show(); }
						else { f.val("").focus(); d.addClass("success").html(l.message).show(); }
                    }
                });
            }
        }
        return false
    });
    $('a[href="#"], a.disabled').click(function(){ return false; });
    (function(d){
        var c = d(".slider").bxSlider({
            controls: true,
            auto: true,
            pause: 20000,
            startingSlide: 0,
            displaySlideQty: 1,
            moveSlideQty: 1,
            pager: true,
            pagerSelector: ".homePager",
            mode: "horizontal",
            infiniteLoop: true,
            speed: 600
        })
    })(jQuery);
    (function(d){
        var c = d(".clslider").bxSlider({
            controls: false,
            auto: false,
            startingSlide: 0,
            displaySlideQty: 1,
            moveSlideQty: 1,
            mode: "fade",
            infiniteLoop: true,
            speed: 600
        });
        d(".clientListSlider li a").click(function () {
	        $linkid = d(this).parent().attr('data-id');
	        c.goToSlide($linkid);
	        d(".clientListSlider li a").removeClass("pager-active");
	        d(this).addClass("pager-active");
	        return false
	    });

        d(".clientPager a:first").addClass("pager-active")
    })(jQuery);

    $("a.WRK img").css({ opacity:".25" });

    $("a.WRK").hover(function () {
        $(this).find("img").stop().animate({ opacity:"1" }, 300);
        $(this).find("span").css({ display: "block" }).stop().animate({ height:"35", opacity:"1" }, 300);
    }, function () {
        $(this).find("img").stop().animate({ opacity:".25" }, 300);
        $(this).find("span").stop().animate({ height:"0", opacity:"0" }, 300);
        return false
    });
    $(".workTabsWrap a").click(function () {
        var f = $(this),
            d = $(this).attr("data-for"),
            c = $(".workGroup"),
            g = $(".workTabsWrap a");
        g.removeClass("current");
        f.addClass("current");
        c.removeClass("active").css({ opacity:"0" });
        c.each(function () {
            if ($(this).hasClass(d)) { $(this).removeClass("hidden"); }
			else { $(this).addClass("hidden"); }
        }).animate({ opacity:"1" }, 550);
        return false
    });

	    function b(g, f, c, d) {
	        // console.log(f);
	        // console.log(c);
	        return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/data/closelabel.gif" /></a></span>' + (g && g.length ? "<b>" + g + "</b>" : "") + "Image " + (c + 1) + " of " + f.length + "</div>"
	    }
	    $(".workGroup a.img").each(function () {
	        var c = $(this);
	        c.fancybox({
	            titleShow: true,
	            autoScale: true,
	            overlayColor: "#000",
	            titlePosition: "over",
	            title: c.attr("data-title"),
	            onComplete: function () {
	                $("a.view").click(function () {
	                    $(this).addClass("hidden");
	                    $("a.hide").removeClass("hidden");
	                    $(".workDetails").stop().css({ height:"auto" }).animate({ opacity:"1" });
	                    return false
	                });
	                $("a.hide").click(function () {
	                    $(this).addClass("hidden");
	                    $("a.view").removeClass("hidden");
	                    $(".workDetails").stop().animate({ height:"0", opacity:"0" });
	                    return false
	                });
	            }
	        })
	    });
	$(".workGroup a.int").each(function () {
	        var c = $(this);
	        var proj = c.attr('href');
	        var ogg = c.attr('data-ogg');
	        var mp4 = c.attr('data-mp4');
	        $('.no-ie video.vid').gVideo();
	        c.fancybox({
	            titleShow:true,
	            autoScale:false,
				scrolling:'no', 
	            overlayColor:"#000",
	            titlePosition:"over",
	            title: c.attr("data-title"),
	            content: '<div id="'+proj+'" style="width:500px;height:auto;">'+
                         '<video style="background:#000;display:block;" width="500" height="300" controls="controls" class="vid">'+
							'<source src="'+ogg+'" type=\'video/ogg; codecs="theora, vorbis"\'/>'+
							'<source src="'+mp4+'" type=\'video/mp4; codecs="avc1.4D401E, mp4a.40.2"\'/>'+
							'<a href="'+mp4+'" style="display:block;width:500px;height:300px;" class="flowPlayer"></a>'+
						 '</video>',
				onStart: function(){
					flowplayer(".flowPlayer", "http://releases.flowplayer.org/swf/flowplayer-3.2.7.swf"); 
				},
	            onComplete: function () {
	            	$('.no-ie video.vid').gVideo();
	                $("a.view").click(function () {
	                    $(this).addClass("hidden");
	                    $("a.hide").removeClass("hidden");
	                    $(".workDetails").stop().css({ height:"auto" }).animate({ opacity:"1" });
	                    return false
	                });
	                $("a.hide").click(function () {
	                    $(this).addClass("hidden");
	                    $("a.view").removeClass("hidden");
	                    $(".workDetails").stop().animate({ height:"0", opacity:"0" });
	                    return false
	                });
	            }
	        })
	    });
	
	$(".workGroup a.ext").each(function () {
	        var c = $(this);
	        c.fancybox({
	            titleShow:true,
	            autoScale:false,
	            overlayColor:"#000",
	            titlePosition:"over",
	            title: c.attr("data-title"),
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: { wmode:'transparent', allowfullscreen:true },
	            onComplete: function () {
	                $("a.view").click(function () {
	                    $(this).addClass("hidden");
	                    $("a.hide").removeClass("hidden");
	                    $(".workDetails").stop().css({ height:"auto" }).animate({ opacity:"1" });
	                    return false
	                });
	                $("a.hide").click(function () {
	                    $(this).addClass("hidden");
	                    $("a.view").removeClass("hidden");
	                    $(".workDetails").stop().animate({ height:"0", opacity:"0" });
	                    return false
	                });
	            }
	        })
	    });
	
    $(".map a.popUp").fancybox({ titleShow:true, width:"75%", height:"75%", autoScale:false, overlayColor:"#000", titlePosition:"over", type:"iframe" });
    
	$("a.clnt, .go_prev2, .go_next2").css({ opacity:".25" });
    $("a.clnt, .go_prev2, .go_next2").hover(function () {
        $(this).stop().animate({ opacity:"1" }, 300);
    }, function () {
        $(this).stop().animate({ opacity:".25" }, 300);
        return false;
    });

	// --------------------------------------------------------------------------------
	// Homepage BG
	// --------------------------------------------------------------------------------
	$bg = $('.main').attr('data-default');
	$('.homebck').css({'background':"url('"+baseurl+$bg+"') center top no-repeat"});

	var $slidenav = $('.clientListSlider').bxSlider({ startingSlide:0, displaySlideQty:5, moveSlideQty:5, mode:'horizontal', infiniteLoop:false, controls:false, speed:600 });
	
	$('.go_prev2').click(function(){ $slidenav.goToPreviousSlide(); return false; });
	$('.go_next2').click(function(){ $slidenav.goToNextSlide(); return false; });	

	$('.no-ie video.vid').gVideo();
});
