/*
 * Insert Script Plugin
 */

jQuery.insert = function(file){
	var data	= [];	var data2	= [];
	if (typeof file == 'object')	{
		data = file;
		file = data.src !== undefined ? data.src : false;
		file = file === false && data.href !== undefined ? data.href : file;
		file = file === false ? file2 : false;
	}
	if (typeof file == 'string' && file.length)	{
		var index	= file.lastIndexOf('.');
		var index2	= file.replace('\\', '/').lastIndexOf('/') + 1;
		var ext		= file.substring(index + 1, file.length);
	}
	switch(ext)	{
		case 'js':	data2 = {elm:'script',	type:'text/javascript',src:file};	break;
		case 'css':	data2 = {elm:'link',	rel:	'stylesheet',	type:	'text/css',	href:	file};	break;
		default:	data2 = {elm: 'link'};	break;
	}
	data2.id = 'script-' + (typeof file == 'string' && file.length ?	file.substring(index2, index) : Math.round(Math.rand() * 100));
	for (var i in data)	{data2[i] = data[i];}
	data	= data2;var tag	= document.createElement(data.elm);
	delete data.elm; for (i in data)	{tag.setAttribute(i, data[i]);}
	jQuery('head').append(tag);	return jQuery('#' + data.id);
};


$(document).ready(function(){ 
	//--| Insert additional files
        $.insert(TEMPLATE_DIR+'/templates/js/jquery.easing.min.js');	

/*
	scrollToTop 
*/         
$(function(){
   	$.fn.scrollToTop=function(options){
   		if(options.speed){
   			var speed=options.speed;
   		}else{
   			var speed="slow";
   		}
   	if(options.ease){var ease=options.ease;}else{var ease="jswing";}
   	if(options.start){var start=options.start;}else{var start="0";}
   	var scrollDiv=$(this);
   	$(this).hide().removeAttr("href");
   	if($(window).scrollTop()>start){$(this).fadeIn("slow");}
   	$(window).scroll(function(){if($(window).scrollTop()>start){$(scrollDiv).fadeIn("slow");}else{$(scrollDiv).fadeOut("slow");}
   	});
   	$(this).click(function(event){$('html, body').animate({scrollTop:0}, '900');});
    }
});  
$(function() { 
	$("a#toTop").scrollToTop({
		start:100}); 
});  
});


               
$(document).ready(function() { 
$(".picturelink a").attr("rel", "cslide");	
	  if($("[rel='csingle'], [rel='cfade'], [rel='cslide'], .colorbox, .youtube, .iframe").length)
            {   
                 $.insert(TEMPLATE_DIR+ '/js/colorbox/jquery.colorbox-min.js');
				

                $(".colorbox").colorbox({
                                                maxWidth:"90%",
                                                maxHeight:"90%",
                                                opacity: "0.7"                                 

                });
		$("a[rel='csingle']").colorbox({
						opacity: "0.7",
                                                maxWidth:"90%",
                                                maxHeight:"90%",
						current: "Bild {current} von {total}"								
                                               });
		$("a[rel='cfade']").colorbox({
                                                 transition:"fade",
                                                 opacity: "0.7",
                                                 maxWidth:"90%",
                                                 maxHeight:"90%",
						 current: "Bild {current} von {total}",
                                                 speed: 800
                                             });
		$("a[rel='cslide']").colorbox({
                                                 slideshow:true,
                                                 slideshowSpeed:6000,
                                                 slideshowAuto:true,
                                                 transition:"elastic",
                                                 speed:500,
                                                 opacity: "0.7",
                                                 maxWidth:"90%",
                                                 maxHeight:"90%",
                                                 previous:"zur&uuml;ck",
                                                 next:"vor",
                                                 close:"schlie&szlig;en",
                                                 current: "Bild {current} von {total}",
                                                 slideshowStart: "Diashow starten",
                                                 slideshowStop: "Diashow anhalten"
                                               });
		$(".youtube").colorbox({
                                                iframe:true,
                                                width:650,
                                                height:550
                                       });
		$(".iframe").colorbox({
                                                width:"90%",
                                                height:"90%",
                                                iframe:true
                                       });
}    
});

