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();
		  
	});

	$(".header_todays_date").append('<span>' + getDate () + '</span>'); 

});


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 countChars(chars, counterid, textid, messagetext) {
		document.getElementById(counterid).value = maxlimit-chars;
		if (chars > 400) { 
			document.getElementById(textid).value = messagetext.substring(0, maxlimit);
		}
} 

function getDate() {

	/* Fetch todays date */  
	oDate = new Date();  

	/* Day */
	sDay = oDate.getDate();  

	/* WeekDay */
	var sWeekDay=new Array(7);
	sWeekDay[0]="S&ouml;ndag";
	sWeekDay[1]="M&aring;ndag";
	sWeekDay[2]="Tisdag";
	sWeekDay[3]="Onsdag";
	sWeekDay[4]="Torsdag";
	sWeekDay[5]="Fredag";
	sWeekDay[6]="L&ouml;rdag";

	/* Month */
	var sMonth = new Array(12);
	sMonth[0]="jan";
	sMonth[1]="feb";
	sMonth[2]="mar";
	sMonth[3]="apr";
	sMonth[4]="maj";
	sMonth[5]="jun";
	sMonth[6]="jul";
	sMonth[7]="aug";
	sMonth[8]="sep";
	sMonth[9]="okt";
	sMonth[10]="nov";
	sMonth[11]="dec";

	/* Year */
	sYear = oDate.getFullYear();  
	return sWeekDay[oDate.getDay()] + ' ' + sDay + ' ' + sMonth[oDate.getMonth()];

}  
