/*jQuery.noConflict(); */

jQuery(document).ready(function() {	
	
	jQuery('object[data*="youtube.com"]').addClass('youtube bordered');
	jQuery('iframe[src*="youtube.com"]').addClass('youtube bordered');
	
	  $('#slider1').bxSlider({
		auto: true,
		controls: false,
		speed: 5000
	  });
	  											
	/* Cufon font replace */
	Cufon.replace('h1, h2, h3, h4, h5, h6, .navfont', { fontFamily: 'Bebas Neue', hover: false, textShadow: '#fff 1px 1px'});
	Cufon.replace('.dividerbig, .dividersmall', { fontFamily: 'Bebas Neue', hover: false, textShadow: '#fff 1px 1px'}); 
	Cufon.replace('.footertitle_white, .footertitle_blue', { fontFamily: 'Bebas Neue', hover: false, textShadow: '#000 1px 1px'}); 	
				      
	/* Image Captions */			
	jQuery("img.captionmeblue").each(function(){
		var captiontext = jQuery(this).attr('title');
		jQuery(this).wrap("<div class='imgpost'></div>");
		jQuery(this).parent().append("<div class='thecaptionblue'>" + captiontext + "</div>");
	});
	jQuery("img.captionmegrey").each(function(){
		var captiontext = jQuery(this).attr('title');
		jQuery(this).wrap("<div class='imgpost'></div>");
		jQuery(this).parent().append("<div class='thecaptiongrey'>" + captiontext + "</div>");
	});
	jQuery("img.captionmered").each(function(){
		var captiontext = jQuery(this).attr('title');
		jQuery(this).wrap("<div class='imgpost'></div>");
		jQuery(this).parent().append("<div class='thecaptionred'>" + captiontext + "</div>");
	});

	/* Hover image opacity */
	jQuery("a[rel^='fadeimg'] img").hover(function() {
		jQuery(this).stop().fadeTo("fast", 0.5); 
	},function(){
		jQuery(this).stop().fadeTo("fast", 1.0); 
	});
	
	/* Pretty Photo */
	addPrettyPhoto();
	
	/* Blog Mini Sidebar Slider */
	addSidebarSlider();
	
	/* Activate smooth tabs */
	if(jQuery('.smoothTabs').length != 0){
		jQuery('.smoothTabs').smoothTabs(200);
	}
	
	/* Portfolio Quicksand */
	addPortfolio('4');
	addPortfolio('3');
	addPortfolio('2');
	addPortfolio('1');
		
});

jQuery(window).load(function() {

	
	/* Nivo Slider */
	if(jQuery('#slider').length != 0){
		jQuery('#slider').nivoSlider({
			effect: 'random',
			slices: 10,
			boxCols: 5,
			boxRows: 4,
			animSpeed: 500,
			pauseTime: 5000,
			startSlide: 0,
			directionNav: false,
			directionNavHide: true,
			controlNav: true,
			controlNavThumbs: true,
			controlNavThumbsFromRel: false,
			controlNavThumbsSearch: '.jpg',
			controlNavThumbsReplace: '_thumb.jpg',
			keyboardNav: true,
			pauseOnHover: true,
			manualAdvance: false,
			captionOpacity: 0.9,
			prevText: 'Prev',
			nextText: 'Next',
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){},
			lastSlide: function(){},
			afterLoad: function(){},
			customChange: function(){
				Cufon.replace('.slidercaption', { fontFamily: 'Bebas Neue', hover: true });
			}
		});
	}
	
	/* Piecemaker Slider */
	addPiecemaker();
	
	/* Google Maps */
	loadGoogleMaps();
	
});

function addPiecemaker(){
	/* 3D Slider */
	if(jQuery('#piecemaker').length != 0){
		jQuery("head").append('<script>swfobject.embedSWF("images/piecemaker2/piecemaker.swf" , "piecemaker", "920", "445", "10", null, flashvars, params, null)</script>');
	}
}

function addSidebarSlider(){
	/* Blog Sidebar Slider */
	if(jQuery('#sidebarslider').length != 0){
		jQuery('#sidebarslider').tinycarousel({ 
			controls: false, 
			pager: true, 
			interval: true, 
			intervaltime: 3000
		});	
	}
}


function addPrettyPhoto() {
	/* PrettyPhoto init */
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'facebook',
		overlay_gallery: true,
		show_title: false,
		hideflash: true
	});
	
	/* PrettyPhoto hover image opacity */
	jQuery("a[rel^='prettyPhoto'] img").hover(function() {
		jQuery(this).stop().fadeTo("fast", 0.5); 
	},function(){
		jQuery(this).stop().fadeTo("fast", 1.0); 
	});	
}

function initGoogleMaps() {
	/* Google Maps Init */
	var myLatlng = new google.maps.LatLng(51.771296, 10.208082);
	var myOptions = {
		zoom: 14,
		center: myLatlng,
		popup: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("googlemap"), myOptions);
}
  
function loadGoogleMaps() {
	/* Google Maps Load */
	if(jQuery('#googlemap').length != 0){
		var script = document.createElement("script");
		script.type = "text/javascript";
		script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initGoogleMaps";
		document.body.appendChild(script);
	}
}

/* jQuery Smooth Tabs version 1.1.0 */
(function($) {  
	$.fn.smoothTabs = function(fadeSpeed) {
		// Visible index
		var currentIndex = 0;
		// Clicked tab class
		var smoothTabsLiCurrent = 'smoothTabsLiCurrent';
		// Hidden div class
		var smoothTabsDivHidden = 'smoothTabsDivHidden';
		// Visible div class
		var smoothTabsDivVisible = 'smoothTabsDivVisible';
		// Current hash if any.
		var hash = document.location.hash.substr(1, document.location.hash.length);

		if (hash && $('#'+hash, this).size()) {
			currentIndex = $('#'+hash, this).index();
		}

		// Makes first tab current, hides all divs and fades in the first one
		this.each(function() {
			$('ul li:eq('+currentIndex+')', this).addClass(smoothTabsLiCurrent);
			$(this).children("div").addClass(smoothTabsDivHidden);
			$('div:eq('+currentIndex+')', this).fadeIn(fadeSpeed)
								.addClass(smoothTabsDivVisible)
								.removeClass(smoothTabsDivHidden);
		});

		// Tab click function
		$('ul li', this).click(function(){
			var $parentUl = $(this).parent();
			var $parentDiv = $($parentUl).parent();
			$('li', $parentUl).removeClass(smoothTabsLiCurrent);
			$(this).addClass(smoothTabsLiCurrent);
			var $clickedIndex = $('li', $parentUl).index(this);
			var $currentDiv = $('div', $parentDiv).get($clickedIndex);
			
			// If current tab is clicked - we're done
			if ($($currentDiv).attr('class') == smoothTabsDivVisible) {
				return false;
			}
			
			// Current div is replaced by the selected one
			$('.'+smoothTabsDivVisible, $parentDiv).fadeOut(fadeSpeed, function(){
				$($currentDiv).fadeIn(fadeSpeed).addClass(smoothTabsDivVisible).removeClass(smoothTabsDivHidden);
			});
			$('.'+smoothTabsDivVisible, $parentDiv).removeClass(smoothTabsDivVisible).addClass(smoothTabsDivHidden);
		});
	};
})(jQuery);
