//GLOBAL
var FFL = window.FFL || {}; //namespace


//HELPERS
//home gallery
FFL.processHomeGallery = function(el) {
	switchHighlight(el, true);
} || window.FFL.processHomeGallery;

var rotator = null;
function switchHighlight(el, useraction){
	if(useraction){
		try{
			clearTimeout(rotator);
		}catch(ignore){}
	}
	
	var o = jQuery(el);
	jQuery("#hl_thumbs a").removeClass("act");
	jQuery(o).addClass("act");
	var newPreviewSrc = jQuery(o).attr("rel"); //clicked thumb rel becomes new preview src
	var newTitleTxt = jQuery(o).attr("title"); //clicked thumb title becomes new title
	var newLinkURL = jQuery(o).attr("href"); //clicked thumb href becomes new More link
	var imageDesc = jQuery(o).children("img").attr("alt"); //big img descr transferred via alt attr
	//update
	jQuery("#hl_portrait_ct h2 span").text(newTitleTxt); //update big img textparagraph
	jQuery("#hl_portrait_ct p").text(imageDesc); //update big img textparagraph
	jQuery(".hl_portrait img").attr("src",newPreviewSrc); //update big img src
	jQuery("#hl_portrait_ct ul li a.ext").attr("href",newLinkURL); //update big img src
	if(newLinkURL.indexOf("http://www.pardo.ch")!=0 && (newLinkURL.indexOf("http://")==0 || newLinkURL.indexOf("https://")==0)){
		jQuery("#hl_portrait_ct ul li a.ext").attr("target","_new");
	}else{
		jQuery("#hl_portrait_ct ul li a.ext").attr("target","");
	}
}

function rotateHighlight(tab,max,delay){
	var el = document.getElementById('hl_tab_'+tab);
	switchHighlight(el, false);
	tab++;
	if(tab == max) tab=0;
	rotator = setTimeout('rotateHighlight('+tab+','+max+','+delay+');', delay);
}

//sub gallery
FFL.processSubGallery = function(el) {
	var o = jQuery(el);
	jQuery("#gallery_thumbs a").removeClass("act");
	jQuery(o).addClass("act");
	var newPreviewSrc = jQuery(o).attr("href"); //clicked thumblink href becomes new preview src
	var newFullSrc = jQuery(o).attr("rev"); //clicked thumblink rev becomes new full src
	var newFullTxt = jQuery(o).attr("title"); //clicked thumblink title becomes new full description
	var newHiRes = jQuery(o).attr("rel"); //clicked thumblink rel becomes new high res url
	//apply new data
	jQuery("#gallery_ct img").attr("src",newPreviewSrc);
	jQuery("#gallery_ct a.lb").attr("href",newFullSrc);
	jQuery("#gallery_ct a.lb").attr("title",newFullTxt);
	if(newHiRes != '') jQuery("#gallery_ct a.hires").attr("href",newHiRes);
} || window.FFL.processSubGallery;

//utils
FFL.util = {
	log: function(text) { //logging debuginfo to console
		if (jQuery.browser.mozilla) {
			console.log(text);
		}
	}
} || window.FFL.util;