//js scripts

//jQuery
jQuery.noConflict();

function zipDownload(galleryId) {
	jQuery.ajax({
		type: "POST",
		url: 'typo3conf/ext/abt_page_erweiterung/class.tx_abtpageerweiterung_pi1.php',
		data: "tx_abtpageerweiterung[galleryId]="+galleryId,
		success: function(){
			alert ("es klappt");
		}
	});
};


//jQuery functions
function imageMapHandler()
{
	var actClassNamefromAttr	= jQuery('.wrapperImageMap').attr('class');
	
	//var attrCutted				= jQuery(actClassNamefromAttr);
	//alert(actClassNamefromAttr);
	
	jQuery('.imageMap_map').mapster(
	{   
		mapKey: 'alt',
		areas: [{
			key: "karree", 
			selected: true
			}],
		altImage: 'fileadmin/templates/skins/skin-psf-111212/css/images/images_imageMap/sauRot.jpg',
		singleSelect: true,
		isDeselectable: false
	});
	
	jQuery(".imageMapText").first().css("display","block");
	
	jQuery('area').click(function() 
	{
		jQuery(".imageMapText").fadeOut(200).stop(false, true);
		var altAttr				= jQuery(this).attr("alt");
		var classWithAttr		= '.' + altAttr; 
		jQuery(classWithAttr).fadeIn(200);
	});
}

function navLogoScroll() {
	//alert(jQuery.browser.msie);
	if(!jQuery.browser.msie || jQuery.browser.version > 7 ) {
		
		var bodyHeight = jQuery('body').innerHeight();
		var footerHeight = jQuery('#footerOuterWrap').height(); //85px
		var bodyWithoutFooter = (bodyHeight-footerHeight);
	
		var logoHeight = jQuery('#masthead').outerHeight();
		var navHeight = jQuery('#globalMenuWrapper').outerHeight();
		var navAndLogoHeight = (logoHeight+navHeight);
	
		if(jQuery('#panelBalken').length)
		{   
			if(bodyWithoutFooter<navAndLogoHeight)
			{
				jQuery('#globalMenuWrapper').css("position","relative");
				jQuery('#masthead').css("position","relative");
				jQuery('#pageOuterWrap').css("top","40px");
				jQuery('body').css("background-attachment","relative").css("top","0px");
			} else
			{
				jQuery('#globalMenuWrapper').css("position","fixed").css("top","214px");
				jQuery('#masthead').css("position","fixed").css("top","40px");
				jQuery('#pageOuterWrap').css("top","40px");
				jQuery('body').css("background-attachment","fixed").css("top","40px");
			}
		} else
		{
			if(bodyWithoutFooter<navAndLogoHeight)
			{
				jQuery('#globalMenuWrapper').css("position","relative").css("top","0px");
				jQuery('#masthead').css("position","relative");
				jQuery('body').css("background-attachment","relative");
			} else
			{
				jQuery('#globalMenuWrapper').css("position","fixed").css("top","174px");
				jQuery('#masthead').css("position","fixed");
				jQuery('body').css("background-attachment","fixed");
			}
		}
	}
}

function marktpreiseTabs()
{	
	function doAnimateTab(obj)
	{
		var thisTab = obj;

		if(!jQuery(thisTab).find(".marktpreise_containerInnerList").hasClass("selected"))
		{
			jQuery('.marktpreise_tab').find(".marktpreise_containerInnerList").animate({
				"height" : "0",
				"margin-top" : "0"
			});

			jQuery('.marktpreise_tab').animate({
				"margin-top" : "0"
			});
		}
		
		if(jQuery(thisTab).hasClass("selected")) {
			jQuery(thisTab).find(".marktpreise_containerInnerList").animate({
				"height" : "270",
				"margin-top" : "50"
			});
        
			jQuery(thisTab).animate({
				"margin-top" : "320"
			});
		}
	}
	
	jQuery('.marktpreise_tab').click(function(){
		
        if (!jQuery(this).hasClass('selected')) {
			jQuery('.marktpreise_tab').removeClass('selected');
			jQuery(this).addClass('selected');
    	}
		else {
			jQuery(this).removeClass('selected');
		}
		doAnimateTab(this);
    });
}

function fancyboxSkin()
{
	// Image Typo3
	jQuery(".abtShopBigImg").fancybox({
	  'zoomSpeedIn': 300,
	  'zoomSpeedOut': 300,
	  'overlayShow': true
	 });
	
	jQuery("a.lightbox").fancybox({
	  'zoomSpeedIn': 300,
	  'zoomSpeedOut': 300,
	  'overlayShow': true
	 });

	// iFrame Content Typo3
	jQuery("a.lightbox-page").fancybox({
	  'zoomSpeedIn': 300,
	  'zoomSpeedOut': 300,
	  'overlayShow': true,
	  'width': 650,
	  'height': 280,
	  'titleShow': false,
	  'autoScale' : true,
	  'type': 'iframe'
	 });
	
	jQuery("a.gastro-page").fancybox({
	  'zoomSpeedIn': 300,
	  'zoomSpeedOut': 300,
	  'overlayShow': true,
	  'width': 655,
	  'height': 500,
	  'titleShow': false,
	  'autoScale' : true,
	  'type': 'iframe'
	 });

	jQuery(".content-page").fancybox({
	  'zoomSpeedIn': 300,
	  'zoomSpeedOut': 300,
	  'overlayShow': true,
	  'titleShow': false,
	  'autoScale' : true,
	  'type': 'iframe'
	 });

}

function iconSet()
{
	jQuery('a[href$=".pdf"]').addClass("pdf").after('<div class="clearOnly"></div>');
	jQuery('a[href$=".doc"]').addClass("doc");
	jQuery('a[href$=".docx"]').addClass("doc");
	jQuery('a[href$=".xls"]').addClass("excel");
	jQuery('a[href$=".ppt"]').addClass("powerpoint");
	jQuery('a[href$=".txt"]').addClass("txt");
	jQuery('a[href$=".rtf"]').addClass("txt");
	jQuery('a[href$=".zip"]').addClass("zip");
	jQuery('a[href$=".rar"]').addClass("zip");
	jQuery('a[href$=".bin"]').addClass("zip");
	jQuery('a[href$=".jpg"]').addClass("picture");
	jQuery('a[href$=".jpeg"]').addClass("picture");
	jQuery('a[href$=".png"]').addClass("picture");
	jQuery('a[href$=".gif"]').addClass("picture");
	jQuery('.vcard a[href*="Mailto"]').addClass("mailto");
	jQuery('.vcard a').filter(function() {
	    return this.hostname && this.hostname !== location.hostname;
	}).addClass("external");

	jQuery('a:has(> img)').removeClass("pdf doc excel powermoint txt zip mailto picture");
	jQuery('a:has(> img)').addClass("hasNoBorder");
}

function navHeaderStop()
{
	var topWithoutNav = (jQuery('.headPic').height())+220;
	var scrollToTop = jQuery(this).scrollTop();
	if (scrollToTop > topWithoutNav)
	{
		if(jQuery('#panelBalken').length)
		{
			jQuery('.headPic').css({
				'position' : 'fixed',
				'top' : '-180px',
				'-webkit-box-shadow' : '0px 15px 15px white',
				'-moz-box-shadow' : '0px 15px 15px white',
				'box-shadow' : '0px 15px 15px white',
				'z-index' : '1000'
			});
			
			jQuery('#headerMenuWrapper').css({
				'top' : '17px',
				'left' : '50%',
				'margin-left' : '-240px',
				'position' : 'fixed',
				'z-index' : '1001'
			});
			
		} else
		{
			jQuery('.headPic').css({
				'position' : 'fixed',
				'top' : '-220px',
				'-webkit-box-shadow' : '0px 15px 15px white',
				'-moz-box-shadow' : '0px 15px 15px white',
				'box-shadow' : '0px 15px 15px white',
				'z-index' : '1000'
			});
			jQuery('#headerMenuWrapper').css({
				'top' : '-17px',
				'left' : '50%',
				'margin-left' : '-240px',
				'position' : 'fixed',
				'z-index' : '1001'
			});
		}
	} else 
	{
		jQuery('.headPic').css({
			'position' : '',
			'top' : '',
			'-webkit-box-shadow' : '',
			'-moz-box-shadow' : '',
			'box-shadow' : '',
			'z-index' : ''
		});
		jQuery('#headerMenuWrapper').css({
			'top' : '',
			'left' : '',
			'margin-left' : '',
			'position' : '',
			'z-index' : ''
		});
	}
}

function adminPanel()
{		
	if(jQuery('#panelBalken').length)
	{
		//jQuery('#globalMenuWrapper').css("position","relative");
		//jQuery('#masthead').css("position","relative");
		jQuery('#pageOuterWrap').css("top","40px");
	} else
	{
		jQuery('#pageOuterWrap').css("top","0px");
	}
}

function scrollToTop()
{
	jQuery('.toTop').click(function(){
		jQuery('html, body').animate({scrollTop:0}, 'fast');
		return false;
	});
}

function jQueryUniform()
{   
	jQuery("input, textarea, select, button").uniform();
}

function mediaDbLink() {
	jQuery('#tn3-mdiaDbLink').attr('href', jQuery('#galMedienDb').val());
}

function mediaDbLinkImg() {
	jQuery('#tn3-mdiaDbLinkImg').attr('href', 'fileadmin/templates/skins/skin-psf-111212/php/download.php?download_file=' + jQuery('.tn3-full-image').children('img:first-child').attr('src'));
}

function mediaDbLinkPrint() {
	//jQuery('#tn3-mdiaDbLinkPrint').attr('href', jQuery('.tn3-full-image').children('img:first-child').attr('src'));
	printWin = window.open('Schweizerfleisch Events', "_blank","height=800,left=100,top=100,width=800,toolbar=no,titlebar=0,status=0,menubar=yes,location= no,scrollbars=1");
	printWin.document.write('<img src="http://www.schweizerfleisch.ch/' + jQuery('.tn3-full-image').children('img:first-child').attr('src') + '" width="100%">');
 	printWin.document.close();
 	printWin.focus();
 	printWin.print();
 	printWin.close();
}

function mediaDbFullScreen() {
//	jQuery('.fGalerieDetail').data('tn3').tn3().fullscreen();


	    var $mytn3 = jQuery('.fGalerieDetail').tn3({
			skinDir: "fileadmin/templates/skins/skin-psf-111212/js/tn3de/tn3/skins",
			skin: "tn3",
	    }).data('tn3');
	    // call fullscreen method on instance of tn3 gallery
	    $mytn3.fullscreen();

}



//////////////////////////////////////////////////////////////////////////////

jQuery(document).ready(function()
{

	jQuery(".headerSlideShow").innerfade({ animationtype: 'fade', speed: 2500, timeout: 12500 });
	
	if (jQuery("#restName").text().length > 0)
	{
		jQuery('#restName').css("display","inline");
	}
	
	// Clear default search text on click.
	if (jQuery('#siteSearchInput').length > 0) {
		defaultSearchValue = jQuery('#siteSearchInput')[0].value;
		jQuery('#siteSearchInput').focus(function() {
			if (jQuery(this)[0].value === defaultSearchValue) {
				jQuery(this)[0].value = '';
			}
		});

		jQuery('#siteSearchInput').blur(function() {
			if (jQuery(this)[0].value === '') {
				jQuery(this)[0].value = defaultSearchValue;
			}
		});
	}
	
	jQuery("ul#footerMenu li").click(function(){
		window.location=jQuery(this).find("a").attr("href");
		return false;
	});
	
	jQuery(".tipsyIcons").tipsy({
		fade: true,
		gravity: "se"
	});
	 	
	// Funktionen aufrufen
	adminPanel();
	fancyboxSkin();
	iconSet();
	marktpreiseTabs();
	scrollToTop();
	jQueryUniform();  
	navLogoScroll();
	imageMapHandler();

});

jQuery(window).scroll(function()
{
	// Funktionen aufrufen
	navHeaderStop();
	navLogoScroll();
});
