// custom functions



jQuery(document).ready(function($) {

    initImageSlider();
    checkForBanner();
    


});

jQuery(document).ready(function($) {
    $('a[rel*=facebox]').facebox();
});




	/*-- Open links with class="external" in new window --*/
	$(document).ready(function(){
		$('a.external').click(function(){
			window.open(this.href);
			return false;
		});
	});

	/*-- Fade in familyAdOrderForm --*/
	$(document).ready(function(){
		$('a.orderAd').click(function(){
			$("#familyAdOrderForm").slideDown("slow");
		});
	});

	/*-- Fade in familyAdOrderForm --*/
	$(document).ready(function(){
		$('a.closeOrderForm').click(function(){
			$("#familyAdOrderForm").slideUp("slow");
		});
	});



	/*-- Flipbox --*/
	$(document).ready(function(){
		
		$("a#mail").attr("href","mailto"+":"+"luca"+"@smas"+"hup.it");
		
		$("#flipBT").click(function(){
			$("#flipBox").flip({
				direction: 'bt',
				color: '#D46419',
				speed: 400,
				content: "<div class='demo_one'>Hello!<br/>I'm a flip-box!<br/> :) </div>"
			});
		});
		$("#flipTB").click(function(){
			$("#flipBox").flip({
				direction: 'tb',
				color: '#B34212',
				speed: 600,
				content: "<div class='demo_two'>Hey!<br/><span style='font-size:14px'>You can change me with<br/><code style='font-family:monospace;padding-left:10px'>content: $('#myId')</code></span><br/><br/>Enjoy!</div>"
			});
		});
		$("#flipLR").click(function(){
			$("#flipBox").flip({
				direction: 'lr',
				color: '#341405',
				content: "<div class='demo_three'>I'm simple html!</div>"
			});
		});
		$("#flipRL").click(function(){
			$("#flipBox").flip({
				direction: 'rl',
				color: '#166665',
				speed: 550,
				content: "<div class='demo_four'>"+$("#footer div:eq(0)").html()+"<br/><span style='font-size:11px'>This is a taken directly <a href='#footer' style='color:#fff'>from</a> this page<code style='display:block;padding:5px;font-family:monospace'>$('#footer div:eq(0)').html()</code></span></div>"
			});
		});
		
		$("#downloadLink").click(function(){
			pageTracker._trackPageview('download_flip');
		});														
	});


	  
	  
	  
	  // When the document loads do everything inside here ...
	  $(document).ready(function(){
		
		// When a link is clicked
		$("a.tab").click(function () {
			
			
			// switch all tabs off
			$(".active").removeClass("active");
			
			// switch this tab on
			$(this).addClass("active");
			
			// slide all content up
			$(".tabContent").slideUp();
			
			// slide this content up
			var content_show = $(this).attr("title");
			$("#"+content_show).slideDown();
		  
		});

});

function initImageSlider() {



    var zap = $('.slideBoxPics');
        if (zap.length > 0) {

            zap.cycle({
                fx: 'fade',
                timeout: 0,
                next: '#next',
                prev: '#prev',
                after: function(curr, next, opts) {
                    var caption = (opts.currSlide + 1) + '/' + opts.slideCount;
                    $('#LabelCount').html(caption);
                },
                before: function() {
                    if ($(this).attr('nodeName') !== 'IMG') {

                        $('span#imgText').html($(this).find('img').attr("Alt"));
                        $('span#imgByline').html($(this).find('img').attr("Title"));


                        var _imgHeight = $(this).find('img').attr('height');


                        if (_imgHeight > 0) {
                            _imgHeight = _imgHeight + 'px';
                            $('.slideBoxPics').css('height', _imgHeight);

                        }
                    }
                    else {
                        $('span#imgText').html($(this).attr("Alt"));
                        $('span#imgByline').html($(this).attr("Title"));




                        var _imgHeight = $(this).attr('height');


                        if (_imgHeight > 0) {
                            _imgHeight = _imgHeight + 'px';
                            $('.slideBoxPics').css('height', _imgHeight);
                        }
                    }

                    

                }

            });

            
        }

        


        var _imgH = $('.slideBoxPics img:first').height();
        var c = $('.slideBoxPics img').length;
        
        if (_imgH === 0) {
            $('#slideBox img').each(function(i, imgObj) {

                if ($(imgObj).height() > _imgH) {
                    _imgH = $(imgObj).height();

                }
            });
        }

        $('#slideBox').css('height', _imgH);


	  }


	 
	  function checkForBanner() {

	      var height = $('#topAd').height();
	      if (height < 10) {
	          $('#topAd').css('display', 'none');
	      }
	      else {

	          $('#topAd').css('display', 'block');
	      }

	      var height = $('#rightAd').height();
	      if (height < 15) {
	          $('#rightAd').css('display', 'none');
	      }
	      else {

	          $('#rightAd').css('display', 'block');
	      }
	  }