var $j = jQuery.noConflict();

// --------------------------
// LOAD THE COMMON FUNCTIONS
// --------------------------
$j(document).ready(function(){	
	sm_filter();
	sm_overlay();
	sm_gotop();
});


// -------------
// CUSTOM SLIDER
// -------------
function sm_customslider(){
	// Lastest works slideshow
	$j('#new-slider').after('<div id="nav">').cycle({
		fx: 'scrollDown', 
	    speedIn:  800, 
	    speedOut: 500, 
	    easeIn:  'easeOutBack', 
	    easeOut: 'easeInQuad',
	    timeout: 6000,
	    delay:  6000,
	    before: onBefore,
	    after: onAfter,
	    pager: '#nav'
	});		
}

function onBefore() { 
    $j('.popup').animate({ opacity : 0},100); 
}

function onAfter() { 
    $j('.popup').animate({ opacity : 1},280); 
}

// ---------------------------
// CUSTOM SLIDER WITHOUT POPUP
// ---------------------------
function sm_customslider_no_popup(){
	// Lastest works slideshow
	$j('#new-slider').after('<div id="nav">').cycle({
		fx: 'scrollDown', 
	    speedIn:  800, 
	    speedOut: 500, 
	    easeIn:  'easeOutBack', 
	    easeOut: 'easeInQuad',
	    timeout: 6000,
	    delay:  6000,
	    pager: '#nav'
	});		
}

// --------------------
// COIN SLIDER SETTINGS
// --------------------
function sm_coinslider(){
	$j('#coin-slider').coinslider({
		width: 960,
		height: 425,
		navigation: true,
		delay: 3000
	});
}


// ------------------
// SMALL WORKS SLIDER
// ------------------
function sm_workslider(){
	// Lastest works slideshow
	$j('#lastest-works').cycle({
		fx: 'scrollHorz',
		easing: 'easeInOutQuad',
	    speed:  'slow', 
	    timeout: 0, 
	    next:   '#arr-next', 
	    prev:   '#arr-prev'
	});	
}

// --------------------
// FANCY BOX SETTINGS
// --------------------
function sm_fancy(){
	// fancy box
	$j('.thumb').fancybox();		
}

// ----------------------
// PORTFOLIO WORKS FILTER
// ----------------------
function sm_filter(){		
	// work filter function
	$j('#filter ul a').click(function() {
		$j(this).css('outline','none');
		$j('#filter ul .current').removeClass('current');
		$j(this).parent().addClass('current');
		
		var filterVal = $j(this).text().toLowerCase().replace(' ','-');
				
		if(filterVal == 'all-works') {
			$j('ul#worklist li.hidden').fadeIn('normal').removeClass('hidden');
		} else {
			
			$j('ul#worklist li').each(function() {
				if(!$j(this).hasClass(filterVal)) {
					$j(this).fadeOut('fast').addClass('hidden');
				} else {
					$j(this).fadeIn('normal').removeClass('hidden');
				}
			});
		}
		
		return false;
	});
}	

// -------
// OVERLAY
// -------
function sm_overlay(){
	// IE FIX
	if($j.browser.msie){
		$j('<span class="overlayIE"></span>').prependTo('a.thumb');
		$j('.overlayIE').css({opacity : 0});
		$j('a.thumb').hover(function(){				
			$j('.overlayIE',this).stop().animate({ opacity : .5},280);
		}, function(){
			$j('.overlayIE',this).stop().animate({ opacity : 0},150);
		});		
	}	
	// img overlay
	$j('<span class="overlay"></span>').prependTo('a.thumb');
	$j('.overlay').css({opacity : 0});
	$j('a.thumb').hover(function(){				
		$j('.overlay',this).stop().animate({ opacity : 1},280);
	}, function(){
		$j('.overlay',this).stop().animate({ opacity : 0},150);
	});
}

// ----------------
// TWITTER SETTINGS
// ----------------
function sm_twitter(){
	// Twitter
	$j("#twitter").getTwitter({
		userName: "simo_m", // your username
		numTweets: 1, // number of loaded tweets
		loaderText: "Loading tweets...",
		slideIn: true,
		slideDuration: 750,
		showHeading: false,
		showProfileLink: false,
		showTimestamp: true
	});	
}

// ------------------------------------
// TWITTER SETTINGS FOR SIDEBAR TWEETS
// ------------------------------------
function sm_twitter2(){
	// Twitter
	$j("#twitter").getTwitter({
		userName: "simo_m", // your username
		numTweets: 2, // number of loaded tweets
		loaderText: "Loading tweets...",
		slideIn: true,
		slideDuration: 750,
		showHeading: false,
		showProfileLink: false,
		showTimestamp: true
	});	
}

// ---------------
// FORM VALIDATION 	
// ---------------
function sm_validate(){
	// form validation						 
	$j('.contact-form').validate({
			rules: {	
						name: {
							required: true,
							minlength: 2
						},
						message: {
							required: true,
							minlength: 10
						}
					},
			submitHandler: function(form) {
				$j(form).ajaxSubmit({
					target: "#result",
					resetForm: true
				});
			}
	});
}

// -------------------
// GOOGLE MAP SETTINGS
// -------------------
function sm_gmap(){
	// google map
	$j("#map").gMap({ 
		zoom: 14,
		markers: [{ 
		latitude: 51.5916824727648,	// change with your latitude
	    longitude: -0.057849884033203125 // change with your longitude
		}]
	});
}

// ------
// GO TOP
// ------
function sm_gotop(){
	$j('a.gotop').click(function(){
		$j('html, body').animate({scrollTop:0}, 600, 'easeInOutQuad');
		return false;				
	});
}


