//Home Style 1 Carousel Callback
function mycarousel_initCallback(carousel) {
	$('#next, .project-slider-next').bind('click', function() {
        carousel.next();
        return false;
    });

    $('#prev, .project-slider-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
    
    $('.slider-nav a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

}
    
function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
	$('.slider-nav a').removeClass('active');
	$('.slider-nav a').eq(idx-1).addClass('active');
	
};

$(function(){ 
	
		
	//IE6 PNG fix
	if($.browser.msie && $.browser.version.substr(0,1) == 6){
		DD_belatedPNG.fix('.mark-featured, .pointer, #prev, #next, #screen, .close, .social-links a');
	}
	
	
		//Menu
	$('#menu ul li').hover(function(){
		$(this).find('.dd-holder:eq(0)').show();
		$(this).find('a:eq(0)').addClass('hover');
	},
	function(){
		$(this).find('.dd-holder:eq(0)').hide();
		$(this).find('a:eq(0)').removeClass('hover');
	});

	//Blink Fields
	 $('.blink').
    focus(function() {
        if(this.title==this.value) {
            this.value = '';
        }
    }).
    blur(function(){
        if(this.value=='') {
            this.value = this.title;
        }
    });
    
    //Animate Home Style 1 Controls 
    $('#prev').hover(function(){
    	$(this).animate({
    		left: '0'
    	},{
    		queue:false,
    		duration:200
    	});
    },
    function(){  
    	$(this).animate({
    		left: '-15px'
    	},{
    		queue:false,
    		duration:200
    	});
    });
    
     $('#next').hover(function(){
    	$(this).animate({
    		right: '0'
    	},{
    		queue:false,
    		duration:200
    	});
    },
    function(){  
    	$(this).animate({
    		right: '-14px'
    	},{
    		queue:false,
    		duration:200
    	});
    });
    
    //Set Width Carousel's Item
    var slider_width = $('.slider-content').width();
    $('.slider-content ul li, slider-content .jcarousel-clip').css("width",slider_width);
    
    //Home Style 1 Carousel
    $('.slider-content ul').jcarousel({
    	auto: 7,
		wrap: "last",
		scroll: 1,
		visible: 1,
		initCallback: mycarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null,
        itemFirstInCallback: mycarousel_itemFirstInCallback
	});
	
	
	
	
    
    //Social Tooltips
	tooltip();	
	
  	

});

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = -25;
		yOffset = -80;		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"<span class='tooltip-pointer'></span></p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

jQuery.fn.center = function(loaded) {
    var obj = this;
    body_width = parseInt($(window).width());
    body_height = parseInt($(window).height());
    block_width = parseInt(obj.width());
    block_height = parseInt(obj.height());
    
    left_position = parseInt((body_width/2) - (block_width/2)  + $(window).scrollLeft());
    if (body_width<block_width) { left_position = 0 + $(window).scrollLeft(); };
    
    top_position = parseInt((body_height/2) - (block_height/2) + $(window).scrollTop());
    if (body_height<block_height) { top_position = 0 + $(window).scrollTop(); };
    
    if(!loaded) {
        
        obj.css({'position': 'absolute'});
        obj.css({ 'top': top_position });
        $(window).bind('resize', function() { 
            obj.center(!loaded);
        });
        $(window).bind('scroll', function() { 
            obj.center(!loaded);
        });
        
    } else {
        obj.stop();
        obj.css({'position': 'absolute'});
        obj.animate({ 'top': top_position }, 200, 'linear');
    }
}





