//common.js

jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	return this;
};

function capWords(str){ 
   var newStr = str;

   var words = newStr.split(" "); 
   for (var i=0 ; i < words.length ; i++){ 
      var testwd = words[i]; 
      var firLet = testwd.substr(0,1); 
      var rest = testwd.substr(1, testwd.length -1) 
      words[i] = firLet.toUpperCase() + rest 
   }
   newStr = words.join(" ");
   return newStr;
}

$(document).ready(function(){

	jQuery('#mycarousel').jcarousel({
        start: 3
    });



	$(".rollover").hover(
	function(){
		if($(this).attr("src").indexOf("-active") == -1) {
			var newSrc = $(this).attr("src").replace(".jpg","-active.jpg#hover");
			$(this).attr("src",newSrc);
		}
	},
	function(){
		if($(this).attr("src").indexOf("-active.jpg#hover") != -1) {
			var oldSrc = $(this).attr("src").replace("-active.jpg#hover",".jpg");
			$(this).attr("src",oldSrc);
		}
	}
	);

var hashArray = new Array('botox', 'hair', 'who', 'approach', 'principles', 'need', 'values', 'faqs', 'leadership', 'membership', 'participate', 'info', 'press');
var navArray = new Array(	'Botox;',
							'Hair Removal',
							'OUR APPROACH',
							'OUR PRINCIPLES',
							'THE NEED FOR BUSINESS FORWARD',
							'OUR VALUES',
							'FAQS',
							'THE LEADERSHIP',
							'MEMBERSHIP',
							'PARTICIPATE',
							'FOR MORE INFORMATION',
							'FOR PRESS INQUIRIES');


if(page=='home'){

$('.scrollDiv').jScrollPane({showArrows:false});

var currentPage;
var currentNav;

function siteInit(){
	currentPage = 'forward';
	currentNav = 'nav0';
}

    $("div.scrollable").scrollable({ 
    	size: 1,
    	speed: 1200,
		onBeforeSeek: function() { 
            this.getItems().fadeTo(500, 0);         
        }, 
        onSeek: function() { 
            this.getItems().fadeTo(900, 1); 
        } 
    }); 

	$(".navClick").click(function () {
		  if(currentPage!=hash){
    	  	var hash = this.href;
    	  	hash = hash.replace(/^.*#/, '');
	      	$.historyLoad(hash);
	      }
	      return false;
	});
	
	function changeTitle(num){
		txt = hashArray[num];
		txt = capWords(txt);
		document.title = "Beauty Park > "+txt;
	}

	function seekScroll(num) {
	    var api = $("div.scrollable").scrollable(); 
	    api.seekTo(num);
    	changeTitle(num);
	}
	
	function pageload(hash) {
    	for(i=0;i<13;i++){
    		if(currentPage==hashArray[i]){
    			num=i;
    			currentHTML = navArray[num-1];
                $('#'+currentNav).html(currentHTML);
      			$('#'+currentNav).removeClass("selected");
      			break;
    		}
    	}
		
	    if(hash) {
	    $("#loadbox").load(hash+".php");
	    
	    	for(i=0;i<13;i++){
	    		if(hash==hashArray[i]){
	    			num=i;
	    			break;
	    		}
			}
			changeTitle(num);
            var currentId = 'nav'+num;
            //$('#'+currentId).prepend("&gt; ");
            //$('#'+currentId).addClass("selected");
            currentNav = currentId;	
	    	seekScroll(num);
	    	currentPage=hash;
	    	currentNav='nav'+num;
	    } else {
			siteInit();	
	    }
	    
	}
	
	$(this).delay(1000,function(){
		$.historyInit(pageload);
    });
	    
} else {

	function seekScroll(num) {
	    var api = $("div.scrollable").scrollable(); 
	    api.seekTo(num);
	}

	function fadeElements(){
		$('#logo').fadeIn('slow');
		$('#oneway').fadeOut('slow');
	
	}

    $("div.scrollable").scrollable({
    	size: 1,
        interval: 10000, 
        loop: false,  
        speed: 1200,
        onBeforeSeek: function() { 
            this.getItems().fadeTo(500, 0.2);         
        }, 
        onSeek: function() { 
            this.getItems().fadeTo(900, 1);
            index = this.getIndex();
            if (index==2){
            	$('#skipButton').fadeIn('slow');
            } else if (index==5){
            	fadeElements();
            }
        }
    });
    
	$(".splashClick").click(function () {
		var splashID = $(this).attr('id');
		if (splashID == 'sc4') {
			seekScroll(1);
		} else {
			splashID = parseInt(splashID.substr(2)) + 2;
			seekScroll(splashID);
		}
	});
    
    seekScroll(1);
    
}


});