//------------------------------//
//	Custom javascript file		//
//								//
//	Create by: 		Grubforce	//
//	Date:			22-9-2010	//
// 	Theme:			Veyron		//
//------------------------------//

//----------------//
//   NAVIGATION   //
//----------------//

// This script ensures the navigation is triggered
$(document).ready(function(){

	$('ul.navigation').superfish({
		animation: {height:'show'}, 			// Animation of the sub menu
		delay: 0
	});
	
});

//-------------------//
//   CUFON REPLACE   //
//-------------------//

// With the small script you can control which text will be formatted into a nice custom font
// The default font for this theme is EDELSANS but feel free to alter this font.
// 
// To implement a new font follow this link: 
// http://cufon.shoqolate.com/generate/
// Then replace the js file in the fonts folder
// Don't forget to change the linkage in the header of all pages ;-)
Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');
Cufon.replace('h4');
Cufon.replace('h5');
Cufon.replace('h6'); 

// Special
Cufon.replace('h4.col_3');

//----------------//
//   PRETTYPHOTO  //
//----------------//

// Using Google maps
function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
}

// Gallery mode
$(document).ready(function(){
	$(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_square',slideshow:2000, autoplay_slideshow: true});
	$(".gallery:gt(0) a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'fast',slideshow:10000});
	
	$("#custom_content a[rel^='prettyPhoto']:first").prettyPhoto({
		custom_markup: '<div id="map_canvas" style="width:260px; height:265px"></div>',
		changepicturecallback: function(){ initialize(); }
	});

	$("#custom_content a[rel^='prettyPhoto']:last").prettyPhoto({
		custom_markup: '<div id="bsap_1237859" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6" style="height:260px"></div><div id="bsap_1251710" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6"></div>',
		changepicturecallback: function(){ _bsap.exec(); }
	});
});

//------------//
//   ON lOAD  //
//------------//

$(window).load(function() {

	// Nivo slider

	$('#nivo_slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:1500, //Slide transition speed
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:true, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '../core_images/B_active_nav_n_slider.png', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
	
});

//----------------------------------//
//   TOGGLE VIEW ON PORTFOLIO PAGE  //
//----------------------------------//

// This small script takes care of the list/grid view option on the portfolio page
// It only functions when you click on the a.grid_view btn, and adds or removes
// the class grid from the unorderd ul#portfolio_wrapper list
$(document).ready(function(){
	
	$("a.grid_view").toggle(function(){
	  $(this).addClass("active"); 
	  $("ul#portfolio_wrapper").fadeOut("fast", function() {
	  	$(this).fadeIn("fast").addClass("grid"); 
		 });
	  }, function () {
      $(this).removeClass("active");
	  $("ul#portfolio_wrapper").fadeOut("fast", function() {
	  	$(this).fadeIn("fast").removeClass("grid");
		});
	}); 
 
});

//----------------------------//
//   PORTFOLIO IMAGE OVERLAY  //
//----------------------------//

$(document).ready(function () {
  $('.portfolio_item a.preview').hover(function () {
    $(this).find('span').stop().fadeTo('normal', 1);
  }, function () {
    $(this).find('span').stop().fadeTo('normal', 0);

  });
});

//----------------------//
//   IMAGE PRELOADER    //
//----------------------//


$(function () {
	$('img.loading').hide();//hide all the images on the page
});
		
var i = 0;//initialize
var int=0;//Internet Explorer Fix
$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
	var int = setInterval("doThis(i)",500);//500 is the fade in speed in milliseconds
});

function doThis() {
	var imgs = $('img.loading').length;//count the number of images on the page
	if (i >= imgs) {// Loop the images
		clearInterval(int);//When it reaches the last image the loop ends
	}
	$('img.loading:hidden').eq(0).fadeIn(500);//fades in the hidden images one by one
	i++;//add 1 to the count
}



