/*--- tabs ---*/
function initTabs(){
	jQuery('div.tabs-box').each(function(){
		var _hold = jQuery(this);
		var _btn = _hold.find('div.tabs-nav li');
		var _box = _hold.find('div.tabs-content div.tab');
		var _a = _btn.index(_btn.filter('.active:eq(0)'));
		if(_a == -1) _a = 0;
		_btn.removeClass('active').eq(_a).addClass('active');
		_box.removeClass('active').css({
			position: 'absolute',
			top:'-9999px',
			left:'-9999px'
		});
		_box.eq(_a).addClass('active').css({
			position: 'relative',
			top:'0',
			left:'0'
		});
		
		_btn.click(function(){
			changeTab(_btn.index(this));
			return false;
		});
		
		function changeTab(_ind){
			if(_ind != _a){
				_btn.eq(_a).removeClass('active');
				_btn.eq(_ind).addClass('active');
				_box.eq(_a).removeClass('active').css({
					position: 'absolute',
					top:'-9999px',
					left:'-9999px'
				});
				_box.eq(_ind).addClass('active').css({
					position: 'relative',
					top:'0',
					left:'0'
				});
				_a = _ind;
			}
		}
	});
}
/*--- function clearInputs ---*/
function clearInputs(){
	jQuery("[type='text'], [type='password']").each(function(){
		this.val = this.value;
		this.onfocus = function() {
			if(this.value == this.val) {jQuery(this).addClass('edit');this.value = '';}
		}
		this.onblur = function() {
			if(this.value == '') {jQuery(this).removeClass('edit');this.value = this.val;}
		}
	});
}
/*--- carousel ---*/
function initCarousel(){
	jQuery('.gallery').galleryScroll({
		btPrev: 'a.btn-prev',
		btNext: 'a.btn-next',
		holderList: 'div',
		scrollElParent: 'ul',
		scrollEl: 'li',
		slideNum: false,
		duration : 1000,
		step: false,
		circleSlide: true,
		disableClass: 'disable',
		funcOnclick: null
	});
}

function initYoutubeLinks(){
    jQuery('#video-tumbnails li a').click(function(e){
        e.preventDefault();
        jQuery('#video-tumbnails li').removeClass('active');
        jQuery(this).parent().addClass('active');
        var $video = jQuery('#video-tumbnails').prev();
        var v_id = jQuery(this).attr('rel');
        var old_url = $video.find('embed').attr('src');//$video.find('param[name=movie]').attr('value');
        var video_params = old_url.replace('http://www.youtube.com/v/', '').split('&');
        if (video_params[0] == v_id)
            return;
        video_params[0] = v_id;
        var new_url  = 'http://www.youtube.com/v/' + video_params.join('&') + '&autoplay=1';
        $video.find('param[name=movie]').attr('value', new_url);
        $video.find('embed').attr('src', new_url);
        $video.parent().prepend('<object width="620" height="376">' + $video.html() + '</object>');
        $video.remove();

    });
}

function initLatestPhotos(){

    jQuery(".photo-gallery li a img").each(function(i, el){
        var bg_img_src = jQuery(el).attr("src").replace('_m.', '_z.') + '?zz=1';        
        jQuery(el).parent().attr('rel', 'prettyPhoto[flickr]').attr('href', bg_img_src);
        jQuery(el).parent().next().attr('href', bg_img_src);
    });
        
    jQuery(".photo-gallery a[rel^='prettyPhoto']").prettyPhoto({
  	theme: 'facebook'
    });
   

}

function replaceURLWithHTMLLinks(text) {
  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  return text.replace(exp,"<a href=\"$1\" rel=\"external\" target=\"_blank\">$1</a>");
}

function initExternalLinks(){
  jQuery('a[rel*=external]').each(function(){
    jQuery(this).attr('target', '_blank');
  });
}

jQuery(function() {
	// this initialises the demo scoll panes on the page.
	jQuery('#pane').jScrollPane({showArrows:true});
});

jQuery(document).ready(function(){ 
	clearInputs();
	initYoutubeLinks();        
	initLatestPhotos();
	initExternalLinks();


    jQuery(".pp_pic_holder").hide();
    jQuery(".pp_overlay").hide();
    jQuery(".ppt").hide();
});

