// Hover move listing
$(document).ready(function() {
	// ---------------------
	// Set cookies and check
	var cookieName = 'firstvisittest';
	$(function() {
    	checkCookie();
	});

	function checkCookie() {
    	if (document.cookie.length > 0 && document.cookie.indexOf(cookieName + '=') != -1) {
            // do nothing, cookie already sent
   		} else {
            // handle jQuery animation

            // set the cookie to show user has already visited
            document.cookie = cookieName + "=1";
    	}
	}

	
	// ----------------------------
	// Enable mega menu for toolbar
	function megaHoverOver(){
		$(this).find(".sub").stop().css({'bottom':'37px'});
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
	}
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  //$(this).hide(); 
		  $(this).css({'bottom':'9000px'});
	  });
	}
	var config = {    
		 sensitivity: 2,    
		 interval: 100,     
		 over: megaHoverOver,  
		 timeout: 500,   
		 out: megaHoverOut   
	};
	// Allow for the music player to be seen for a brief second before fading out
	$("#toolbarCntnt .right ul li .sub").delay(6000).fadeTo('fast', 0, function() {
		  //$(this).hide(); 
		  $(this).css({'bottom':'9000px'});
	});
	//$("#toolbarCntnt .right ul li .sub").css({'opacity':'0'});
	$("#toolbarCntnt .right ul li").hoverIntent(config);
	
	
	// cufon
	Cufon.replace('.custom, .link-button, #nav>li>a, #social-bar, h2, h3, h4, h5, h6, .bullet-title .big, .bullet-title .small, .title, .subtitle, .portfolio-sidebar ul li a, .post-title, #sidebar ul li a, .staff .information .header .name, .headline', { 
				fontFamily: fontFamilyName,
				hover: true	
	});
	
	// rollovers
	$("#sidebar li ul li.cat-item a, .portfolio-sidebar ul li a").hover(function() { 
		// on rollover	
		$(this).stop().animate({ 
			marginLeft: "7" 
		}, "fast");
	} , function() { 
		// on out
		$(this).stop().animate({
			marginLeft: "0" 
		}, "fast");
	});
	
	// twitter 
    getTwitters('twitterCntnt', {
        id: twitter_user, 
        prefix: '',  // If you want display your avatar and name <img height="16" width="16" src="%profile_image_url%" /><a href="http://twitter.com/%screen_name%">%name%</a> said:<br/>
        clearContents: false, // leave the original message in place
        count: 1, 
        withFriends: true,
        ignoreReplies: false,
        newwindow: true,
        template: '<div class="twitter-entry">"%text%" <br/><span class="twitter-time">%time%</span> </div>'

    });
	
	//superfish
	$("ul.sf-menu").superfish({
		  autoArrows:  false, // disable generation of arrow mark-up
		  animation: {height:'show'},
		  speed: 'fast'
	}); 
	
	// nivo slider
	$('#slider').nivoSlider({
		effect: slideshow_fx, //Specify sets like: 'fold,fade,sliceDown'
        slices: slideshow_slices,
        animSpeed: slideshow_speed, //Slide transition speed
        pauseTime: slideshow_timeout,
        startSlide: slideshow_starting, //Set starting Slide (0 index)
        directionNav: slideshow_directionNav, //Next & Prev
        directionNavHide: slideshow_directionHover, //Only show on hover
        controlNav: slideshow_controlNav, //1,2,3...
        controlNavThumbs: false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance: false, //Force manual transitions
        captionOpacity:0.7 //Universal caption opacity
	}); 
		
	// shortcut nivo slider
	$('#slider2').nivoSlider({}); 

	//  slide fade
	$('.slide-fade').cycle({ 
		fx:     'fade', 
		speed:  500, 
		timeout: 3000, 
		pause: 1
	});
	
	//  slide scroll
	$('.slide-scroll').cycle({ 
		fx:     'scrollHorz', 
		speed:  500, 
		timeout: 3000, 
		pause: 1
	});
	
	// toggle
	$(".toggle-container").hide(); 
	$(".toggle-trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false;
	});
	
	// accordion
	$('.accordion-container').hide(); 
	$('.accordion-trigger:first').addClass('active').next().show();
	$('.accordion-trigger').click(function(){
		if( $(this).next().is(':hidden') ) { 
			$('.accordion-trigger').removeClass('active').next().slideUp();
			$(this).toggleClass('active').next().slideDown();		}
		return false;
	});
	
	// Poshytips
    $('.poshytip').poshytip({
    	className: 'tip-twitter',
		showTimeout: 1,
		alignTo: 'target',
		alignX: 'center',
		offsetY: 5,
		allowTipHover: false
    });
    
     // Poshytips Forms
    $('.form-poshytip').poshytip({
		className: 'tip-yellowsimple',
		showOn: 'focus',
		alignTo: 'target',
		alignX: 'right',
		alignY: 'center',
		offsetX: 5
	});
	
	// tooltip
	$.tools.tooltip.addEffect("fade",
		// opening animation
		function(done) {
			this.getTip().fadeIn();
			done.call();
		},
		// closing animation
		function(done) {
			this.getTip().fadeOut();
			done.call();
		}
	);
	$(".tool").tooltip({
		effect: 'fade',
		offset: [50, 0]
	});
	$(".tool-right").tooltip({
		effect: 'fade',
		position: 'center right',
		offset: [0, -50],
		tipClass: 'tooltip-right'
	});
	$(".tool-bottom").tooltip({
		effect: 'fade',
		position: 'bottom center',
		offset: [-50, 0],
		tipClass: 'tooltip-bottom'
	});
	$(".tool-left").tooltip({
		effect: 'fade',
		position: 'center left',
		offset: [0, 50],
		tipClass: 'tooltip-left'
	});
	$(".social-tooltip").tooltip({
		effect: 'fade',
		offset: [0, 0],
		tipClass: 'tooltip-social'
	});
	
	// tabs
	$('.tabbed').tabs({
		fxFade: true
	});
	
	// pretty photo
	$("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'light_square'
	});	
		
//close			
});
//
$(function() {

    $("#s").focus(function() {
        if ($(this).val() == "Search...") {
            $(this).val("");
        }
    });
    
    if ($(".widget_categories li").length%2 != 0) {
        $(".widget_categories ul").append("<li><a>&nbsp;</a></li>");
    }
    
    if ($(".widget_tag_cloud a").length%2 != 0) {
        $(".widget_tag_cloud").append("<a>&nbsp;</a>");
    }
    
    $(".home li.home").removeClass("home").addClass("current_page_item");
    $("#column-wrap").append("<img src='/images/ajax-loader.gif' id='ajax-loader' />");
            
    var $mainContent = $("#bodyLyt"),
        URL = '',
        siteURL = "http://" + top.location.host.toString(),
        $internalLinks = $("a[href^='"+siteURL+"']"),
        hash = window.location.hash,
        $ajaxSpinner = $("#ajax-loader"),
        $el, $allLinks = $("a");
        
    function hashizeLinks() {
        $("a[href^='"+siteURL+"']").each(function() {
            $el = $(this);
            
            // Hack for IE, which seemed to apply the hash tag to the link weird
            if ($.browser.msie) {
                $el.attr("href", "#/" + this.pathname)
                .attr("rel", "internal");
            } else {
                $el.attr("href", "#" + this.pathname)
                 .attr("rel", "internal");
            }
        });
    };
    
    hashizeLinks();  
        
    $("a[rel='internal']").live("click", function() {
        $ajaxSpinner.fadeIn();
/*        $mainContent.animate({ opacity: "0.1" });*/
       $el = $(this);
        $(".current_page_item").removeClass("current_page_item");
        $allLinks.removeClass("current_link");
        URL = $el.attr("href").substring(1);
        URL = URL + " #inside";
        $mainContent.load(URL, function() {
            $el.addClass("current_link").parent().addClass("current_page_item");
            /*$ajaxSpinner.fadeOut();
            $mainContent.animate({ opacity: "1" });*/
            hashizeLinks();
			Cufon.refresh();
			
				// nivo slider
	$('#slider').nivoSlider({
		effect: slideshow_fx, //Specify sets like: 'fold,fade,sliceDown'
        slices: slideshow_slices,
        animSpeed: slideshow_speed, //Slide transition speed
        pauseTime: slideshow_timeout,
        startSlide: slideshow_starting, //Set starting Slide (0 index)
        directionNav: slideshow_directionNav, //Next & Prev
        directionNavHide: slideshow_directionHover, //Only show on hover
        controlNav: slideshow_controlNav, //1,2,3...
        controlNavThumbs: false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance: false, //Force manual transitions
        captionOpacity:0.7 //Universal caption opacity
	}); 
        });
		
    });
    
    $("#searchform").submit(function(e) {
        $ajaxSpinner.fadeIn();
        $mainContent.animate({ opacity: "0.1" });
        $el = $(this);
        $(".current_page_item").removeClass("current_page_item");
        $allLinks.removeClass("current_link");
        URL = "/?s=" + $("#s").val() + " #inside";
        $mainContent.load(URL, function() {
            /*$ajaxSpinner.fadeOut();
            $mainContent.animate({ opacity: "1" });*/
           alert('success'); /*hashizeLinks(); */  
			
        });
        e.preventDefault();
    });
    
    if ((hash) && (hash != "#/")) {
        $("a[href*='"+hash+"']").trigger("click");
    }

});

/*$(document).ajaxComplete(function() {
	
	alert('success');
	Cufon.refresh();
});*/

// search clearance	
function defaultInput(target){
	if((target).value == 'Search...'){(target).value=''}
}

function clearInput(target){
	if((target).value == ''){(target).value='Search...'}
}

