var j = jQuery.noConflict();
j(document).ready(function () {
    // Fading the social icons
    j('ul.socialIcons li a').css("opacity", .5);
    j('ul.socialIcons li a').hover(function () {
        j(this).stop().animate({
            opacity: 1
        }, 'fast');
    }, function () {
        j(this).stop().animate({
            opacity: .5
        }, 'fast');
    })

    j('a.fade').css("opacity", 1);
    j('a.fade').hover(function () {
        j(this).stop().animate({
            opacity: .7
        }, 'fast');
    }, function () {
        j(this).stop().animate({
            opacity: 1
        }, 'fast');
    })

    //Fading the home button
    j('a.home').hover(function () {
        j(this).stop().animate({
            opacity: .8
        }, 'fast');
    }, function () {
        j(this).stop().animate({
            opacity: 1
        }, 'fast');
    })


    j("ul.sf-menu").supersubs({
        minWidth: 15,
        maxWidth: 28,
        extraWidth: 1
    }).superfish({
        delay: 1000,
        animation: {
            opacity: 'show',
            height: 'show'
        },
        speed: 'fast',
        autoArrows: true,
        dropShadows: false,
    });

})


//Homepage slider
j(window).load(function () {



    //image_fader portfolio
    j("img.hover_fader").hide();
    j(".gallery li").hover(function () {
        j(this).find('img').stop().fadeIn(200);
    }, function () {
        j(this).find('img.hover_fader').stop().fadeOut(200);
    })


    /* Fade toggler ***************************************************************/

    j.fn.fadeToggle = function (speed) {
        return this.animate({
            opacity: 'toggle'
        }, speed);
    }


    j('div.fullworkcontent').hide();

    j("a.trigger").click(function () {
        j("div.fullworkcontent").fadeToggle(150);
        j(this).toggleClass("active");
        return false;
    })

    j("a.closecontent").click(function () {
        j("div.fullworkcontent").fadeToggle(150);
        return false;
    });


    // jQuery Flip 
    j('.sponsorFlip').bind("click", function () {
        var elem = j(this);
        if (elem.data('flipped')) {
            elem.revertFlip();

            elem.data('flipped', false)
        }
        else {
            elem.flip({
                direction: 'lr',
                speed: 350,
                onBefore: function () {
                    elem.html(elem.siblings('.sponsorData').html());
                }
            });
            elem.data('flipped', true);
        }
    })
    // Activate the tipsy
    // For the social menu
    j('[rel=tipsy]').tipsy({
        fade: true,
        gravity: 'n',
        offset: 15
    })

    // For the comment form
    j('form#commentform [title]').tipsy({
        trigger: 'focus',
        gravity: 'w',
        offset: 10,
        fade: true
    })

    //For normal links
    j('.tipsyw').tipsy({
        gravity: 'w',
        offset: 10,
        fade: true
    })
    j('.tipsyn').tipsy({
        gravity: 'n',
        offset: 10,
        fade: true
    })
    j('.tipsys').tipsy({
        gravity: 's',
        offset: 10,
        fade: true
    })
    j('.tipsye').tipsy({
        gravity: 'e',
        offset: 10,
        fade: true
    })


    // Focus - Blur the search form
    j('input.search').each(function () {
        if (this.value == '') {
            this.value = 'Search here'
        }
    })

    j('input.search').focus(function () {
        if (this.value == 'Search here') {
            this.value = ''
        }
    })

    j('input.search').blur(function () {
        if (this.value == '') {
            this.value = 'Search here'
        }
    })


    /* Tabs */

    function Tabs() {

        j("#nav-tabs .tab-content").hide();
        j("#nav-tabs ul.tabs li:first").addClass("active").show();
        j("#nav-tabs .tab-content:first").show();

        j("#nav-tabs ul.tabs li").click(function () {

            j("#nav-tabs ul.tabs li").removeClass("active");
            j(this).addClass("active");
            j("#nav-tabs .tab-content").hide();

            var activeTab = j(this).find("a").attr("href");
            j(activeTab).fadeIn();
            return false;
        })

        j("#post-tabs .tab-content").hide();
        j("#post-tabs ul.tabs li:first").addClass("active").show();
        j("#post-tabs .tab-content:first").show();

        j("#post-tabs ul.tabs li").click(function () {

            j("#post-tabs ul.tabs li").removeClass("active");
            j(this).addClass("active");
            j("#post-tabs .tab-content").hide();

            var activeTab = j(this).find("a").attr("href");
            j(activeTab).fadeIn();
            return false;
        })

    }
function infoFade() {	
	j('div.gallery-img').hover(
		function () {
        	j(this).find('a.gallery-over').stop().fadeTo('fast', 1);
        	},
        function () {
        	j(this).find('a.gallery-over').stop().fadeTo('fast', 0);
      	}
	);
}
    j(document).ready(function () {
        Tabs();
		infoFade();
    })


});
