$(document).ready(function(){
    setupCufont();
    navMenu();
    $(".tooltip").tooltip();
    searchBox();
	$(window).load(function(){
		twitter();
	})
	scrolltop();
});

function setupCufont(){	
    Cufon.replace("h1, h2, h3, h4, h5, h6, .title_slogan, .view_portfolio, .visite_project, .P_pagesNav span");	
	Cufon.replace('#nav li a, #page_title h1, .title_slogan', {textShadow: '1px 1px 3px rgba(0, 0, 0, 0.3)'});	
	Cufon.replace('#nav li ul a', {
		 color: '#000 !important',
		textShadow: '1px 1px 3px rgba(0, 0, 0, 0.2)'
		});
				
	Cufon.replace('#footer h3', {textShadow: '1px 1px 3px rgba(0, 0, 0, 0.4)'});
	Cufon.replace('#page_title h1, .title_slogan', {textShadow: '1px 1px 3px rgba(0, 0, 0, 0.3)'});
}

function navMenu(){
	jQuery('ul.sf-menu').supersubs({
		minWidth: 15, // minimum width of sub-menus in em units 
		maxWidth: 25, // maximum width of sub-menus in em units 
		extraWidth: 1 // extra width can ensure lines don't sometimes turn over 
		// due to slight rounding differences and font-family 
	}).superfish({
						delay:500, // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:	'fast',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false
	});

}

function twitter(){
	 getTwitters('twitterMSG', {
        id: 'envato', 
        prefix: '<a href="http://twitter.com/%screen_name%">%name%</a> said: ', 
        clearContents: false, // leave the original message in place
        count: 2, 
        withFriends: true,
        ignoreReplies: false,
        newwindow: true
    });
}

function scrolltop(){	
	var windowHeight  = $(window).height()/2;
	var target = $("#topArrow").fadeOut();
	var targetAttr = $("#topArrow").attr("href"); 
			
	$(window).scroll(function(){
		var Scrol = $(window).scrollTop();
		if (Scrol > windowHeight) {
			$(target).fadeIn(500);
		}
		if (Scrol < windowHeight) {
			$(target).fadeOut(500);
		}
	})  
    $('#topArrow').click(function(){
        $('html, body').animate({
            scrollTop: $(targetAttr).offset().top
        }, 750, 'easeOutExpo');
    });
}

function searchBox(){
    var boxSkin = $('#search_field');
    var searchBox = $('#search-field').val('');
    var searchBoxAutoPlayAllowed = true;
    var searchBoxPlayText = true;
    var searchBoxText = 'Type your search here...';
    var searchBOxTextPos = 0;
    var searchBoxTimer = null;
    var Activater = null;
    
    if (searchBoxPlayText) {
        Activater = setTimeout(searchBoxAutoPlay, 16000);
    }
    
    function searchBoxAutoPlay(){
        var length = searchBoxText.length
        searchBOxTextPos++
        if (searchBOxTextPos > length) {
            searchBox.val("");
            searchBOxTextPos = 0;
        }
        var timeOut = 70;
        if (searchBOxTextPos == length) {
            timeOut = 6000;
        }
        var substr = searchBoxText.substr(0, searchBOxTextPos);
        searchBox.val(substr);
        searchBoxTimer = setTimeout(searchBoxAutoPlay, timeOut);
    }
    
    searchBox.focus(function(){
        searchBoxPlayText = false;
        searchBox.val("");
        clearTimeout(searchBoxTimer);
    });
    
    searchBox.blur(function(){
        searchBoxPlayText = true;
        searchBox.val('');
        searchBoxTimer = setTimeout(searchBoxAutoPlay, 20000);
    });
}

