//Dom Ready Function
$(document).ready(function() {

	//Hide the welcome note
	$('#notice .exit').click(function(){
		$("#notice").fadeOut('slow', function() {
			$(this).hide();
		});
	});
	
	$('#pagesTable tr:even').addClass('altRow'); 
	
	/*$('#pagesTable').tableDnD({
        onDrop: function(table, row) {
            alert($.tableDnD.serialize());
        }
    });*/
    /*$('#pagesList').sortable({ opacity: 0.6, cursor: 'move', update: function() {
    	    alert('test');

    	
    }});*/
    
	/*jQuery('#pagesTable').tableDnD({

	    onDrop: function (table, row) {

      		$.ajax({
	            type: 'POST',
	            url: '/index.php/admin/ajax',
	            data: {data: jQuery.tableDnD.serialize()},
	            success: function(data) {
	            //--- remove the loading gif and replace with the job no. 
	              alert(data);  
	            }
	        });
		}
	     jQuery.ajax({
	        type:'POST',
	        dataType:'json',
	        data:jQuery.tableDnD.serialize(),
	        success:function(response){
	          jQuery('#pagesTable').ajaxLoaderRemove();
	          jQuery('#confirmationMessage').html(response.message).delay(400)
	                                        slideDown(400).delay(3000).slideUp(400);
	        },
	        beforeSend:function(){
	          jQuery('#pagesTable').ajaxLoader();
	        },
	        error : function(request, textStatus, errorThrown) {
	        	                                        alert(request);

	          jQuery('#pagesTable').ajaxLoaderRemove();
	          //jQuery('#confirmationMessage').html('Oooops!!!.. A problem occurs when ordering items.').delay(400).slideDown(400).delay(3000).slideUp(400);
	          jQuery('#confirmationMessage').html('Oooops!!!.. A problem occurs when ordering items.');
	        },
	        url:"https://www.mobillo.net/admin/ajax"});
	        return false;
	    
	 });*/
	$('a[rel*=facebox]').facebox();
	//Cufon.replace('.main h2', { fontFamily: 'Helvetica Neue'});
	//Cufon.replace('#title h1', { fontFamily: 'Helvetica Neue'});
		
	// initialize slideshow (Cycle)
    if ($('#slider').length > 0) {
		$('#slider').cycle({ 
			fx: 'scrollHorz',
			//fx: 'fade',
			speed: 750,
			timeout: 7200, 
			randomizeEffects: false, 
			easing: 'easeOutCubic',
			next:   '.slideNext', 
			prev:   '.slidePrev',
			pager:  '#nav',
			cleartypeNoBg: true
		});
	 }

	//Home Services Slider
	if ($('.homeServiceList').length > 0) {
		$('.homeServiceList').cycle({ 
			fx: 'scrollHorz',
			speed: 750,
			timeout: 6000, 
			randomizeEffects: false, 
			easing: 'easeOutCubic',
			pager:  '#servicesNav',
			cleartypeNoBg: true
		});
	 }
	 //Home Blog Slider
	if ($('.homeBlogList').length > 0) {
		$('.homeBlogList').cycle({ 
			fx: 'scrollHorz',
			speed: 750,
			timeout: 7000, 
			randomizeEffects: false, 
			easing: 'easeOutCubic',
			pager:  '#blogNav',
			cleartypeNoBg: true
		});
	 }
	//Slider
	$('ul.workSlides').cycle({
		fx:			'fade',
		speed:		1500,
		timeout:	6500,
        pager:  '#workNav',
	});
	// Hover for homepage client-banner project list
var hoverAnim = {
	init: function() {
		var project = $('.moreWorkList li');
		var projectTxt = project.children('.hover');
		var projectInfo = project.children('.project-info');
		var originalBG = "#008aff"; 
		var fadeColor = "#008aff";
		
 		project.children('.hover').fadeTo(1, 0.0)
 			
		project.hover(
			function () {
				$(this).children('.hover').stop().fadeTo(600, 1);
				$(this).children().children('.hover-bg').stop().fadeTo(600, 0.5);
				//$(this).children('.project-info').stop().animate({backgroundColor:fadeColor}, 750);
			}, 
			function () {
				$(this).children('.hover').stop().fadeTo(800 , 0.0);
				$(this).children().children('.hover-bg').stop().fadeTo(600, 0);
				//$(this).children('.project-info').stop().animate({backgroundColor:originalBG},850);
			}
		);
		
	}
};
hoverAnim.init();


//nav effect
	/*$('ul#menu>li').each(function() {
		var li = $(this), h = li.height()-li.find('a').height(), w = li.width();
		li.append('<div class="grnbox"></div>');
		
		var box = li.find('.grnbox');
		box.css({'width':w, 'margin-left':-1*(w/2)});
		
		li.hover(function() {
			box.animate({top:5}, {queue:false, duration:200});
		}, function() {
			box.animate({top:0}, {queue:false, duration:200});
		});
		
	});
*/

	$("dd a img").each(function() { //Thumbnail rollovers
		$(this).append("<span class=\"viewProj\"></span>");
	});

	$("dd a img").hover(
		function() {
			$(this).stop().fadeTo(300, .6);
		},
		function() {
			$(this).stop().fadeTo(300, 1)
		}
	);

//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	//Striping
	$('.serv > li:even').addClass('alt');
	$('.serv2 > li:even').addClass('alt');
	$('.capabilities > li:even').addClass('alt');

	$('.work li a').hover(
    function() {
        $(this).stop().animate({backgroundColor:'#3a92c4'}, 300);
        $(this).children("img").stop().fadeTo(300, 0.5);
    }, function () {
        $(this).stop().animate({backgroundColor:'#5bc0f9'}, 100);
        $(this).children("img").stop().fadeTo(300, 1);
    });
	
	//Logo
	
	$(".logo").hover(
		function() {
			$(this).stop().fadeTo(300, .6);
		},
		function() {
			$(this).stop().fadeTo(300, 1)
		}
	);
	
	$('.link2').hover(function() {
	        $(this).stop().animate({backgroundColor:'#e80000', color: '#fff'}, 300);
	}, function () {
	        $(this).stop().animate({backgroundColor:'#161617', color: '#fff'}, 300);
	});
	
	//Link Hover
	/*$('.menu li a').hover(function() {
	        $(this).stop().animate({borderTopColor:'#e80000', color: '#ffa800'}, 300);
	}, function () {
	        $(this).stop().animate({borderTopColor:'#161617', color: '#fff'}, 200);
	});*/
	
	/*$(".menu li").not('.current_page_item').prepend("<span></span>"); //Throws an empty span tag right before the a tag
	
	$(".menu li").each(function() { //For each list item...
		var linkText = $(this).find("a").html(); //Find the text inside of the a tag
		$(this).find("span").show().html(linkText); //Add the text in the span tag
	}); 
	
	$(".menu li").hover(function() {	//On hover...
		
		$(this).not('.current_page_item').find("span").stop().animate({ 
			marginTop: "-20" //Find the span tag and move it up 40 pixels
		}, 300);
	} , function() { //On hover out...
		$(this).not('.current_page_item').find("span").stop().animate({
			marginTop: "0" //Move the span back to its original state (0px)
		}, 300);
	})*/

	
	//Twitter
	getTwitters('tweet', { 
	  id: 'webtecmedia', 
	  count: 1, 
	  enableLinks: true, 
	  ignoreReplies: true, 
	  clearContents: true,
	  template: '"%text%" <a href="http://twitter.com/%user_screen_name%/statuses/%id%/" class="small-link">%time%</a>'
	});
	$(".grey").hide();
	$(".morebtn").click(function () {
      $(".grey").slideToggle("slow");
      return false;
    });
    
	var fadeDuration = 250; //time in milliseconds
    $('#sidebar-right ul li a').hover(function(){
	    $(this).animate({ paddingLeft: '1em' }, fadeDuration);
      }, function() {
        $(this).animate({ paddingLeft: '0' }, fadeDuration);
    });
	
	$('#sidebar ul li a').hover(function(){
	    $(this).animate({ paddingLeft: '1em' }, fadeDuration);
      }, function() {
        $(this).animate({ paddingLeft: '0' }, fadeDuration);
    });

	
});
