/*
 * this script based on Thickbox 3.1 by Cody Lindley (http://www.codylindley.com)
 * and was modified by peppermind (http://www.peppermind.de)
 * Copyright (c) 2008 peppermind
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
var tb_pathToImage = "/img/teaser/home/schaufenster/sf_ajax-loader.gif";
//on page load call tb_init
$(document).ready(function(){   
	tb_init('a.detailbox');//pass where to apply the box
	imgLoader = new Image();//preload image
	imgLoader.src = tb_pathToImage;
});

//add the box to href & area elements that have a class of .detailbox
function tb_init(domChunk){
  $(domChunk).unbind("click");
  $(domChunk).click(function(){
  tb_show(this.href);
  this.blur();
  return false;
  });
}

function tb_show(url) {//function called when the user clicks on a .detailbox link
	try {
		if(document.getElementById("TB_overlay") === null){
			$("#sf_carousel_container").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
			$("#TB_overlay").click(tb_remove);
		}
    
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
    
   	        $("#sf_carousel_container").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$("#TB_load").show();//show loader
		
		$("#TB_window").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
	   	    $("#TB_load").remove();
                    $("#TB_window").css({display:"block"});
                    $("#TB_window #sf_image a img").pngfix({imageFixSrc:'/img/x.gif'});
		});
	} catch(e) {
		//nothing here
	}
}

//helper functions below
function tb_remove() {
  $("#TB_window").fadeOut("fast",function(){$("#TB_window,#TB_overlay").trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	return false;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}


