jQuery(document).ready(function(){
	
    if ($.browser.mozilla) {
        $("div#header-slider-inner").css({
            margin: '51px 0 0 1px'
        });
    }
				
    // portofolio
    avio_portfolio();	
			  
    // dropdown menu
    avio_dd_menu();

    // display your tweets info @ http://code.google.com/p/twitterjs/ or http://remysharp.com/2007/05/18/add-twitter-to-your-blog-step-by-step/
    avio_tweets(3, "thaberkern");// 1 = number of tweets 2 = username
		
    // basic jqyuery animate
    avio_animate();
		
    // login
    //avio_login();
	
    // lightbox info @ http://www.pirolab.it/pirobox/
    avio_lightbox();	
    
    // google maps info @ http://googlemaps.mayzes.org/
    //avio_gmaps();
		
    // animated scroll to top	
    avio_scroll_top();
	
    		
    // basic jquery equal height, used for the content and sidebar
    //avio_equalHeight(jQuery("#content-inner-page, #sidebar"));
		
    // preload images 
    $(".preload_all, .kwicksSlider").img_preloader ({
        delay:200
    });
		

}); 
//---//
function avio_portfolio(){
    jQuery(".jcap-caption").hover(function(){
        img_wdt = jQuery('.jcap').width() -40;
        img_hgt = jQuery('.jcap').height() -40;
        jQuery(this).css({
            backgroundImage: "none"
        })
        .stop(true, true).animate({
            height: img_hgt, 
            width: img_wdt
        }, 300)
        .children('div').stop(true, true).delay(200).fadeIn(1);
    }, function(){
        jQuery(this).delay(100).css({
            backgroundImage: ""
        })
        .animate({
            height: '10px', 
            width: '10px'
        }, 300)
        .children('div').hide(10);	
    });
}

//---//
function avio_equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = jQuery(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}
//---//
function avio_gmaps(){	
    alert ('blubb');
    $('#sidebar-maps').googleMaps({
        latitude: 42.351505,
        longitude: -71.094455,
        markers: {
            latitude: 	42.351505,
            longitude: -71.094455,
            draggable: true,
            info: {
                layer: '#ginfo'
            }
        }
    });
}		
//---//
function avio_dd_menu(){	
    //dropdown menu
    jQuery("ul#header-menu li").hover(function(){
        jQuery(this).stop().find('ul:first').css({
            visibility: "visible",
            display: "none"
        }).animate({
            height: 'toggle'
        }, 200);
    }, function(){
        jQuery('ul:first',this).css('visibility', 'hidden');
    });
			
    // add arrow first lvl
    jQuery('.second-lvl').parent("li").addClass('arrowdown');

    // add arrow second lvl
    jQuery('.third-lvl').parent("li").addClass('arrowright');
						
    // add an active class to the parent li
    jQuery(".second-lvl").hover(function(){
        jQuery(this).parent("li").addClass("active");							
    }, function(){
        jQuery(this).parent("li").removeClass("active");	
    });
}
//---//
function avio_animate(){
    // read more links 
    jQuery(".content-3col .readmore").hover(function(){
        jQuery(this).stop().animate({
            width: "156px"
        }, 150);				   
    },function(){ 
        jQuery(this).stop().animate({
            width: "62px"
        }, 150);	
    });
}
//---//
function avio_login(){
    // center the box
    jQuery.fn.center = function (absolute) {
        return this.each(function () {
            var t = jQuery(this);
            t.css({
                position:    absolute ? 'absolute' : 'fixed', 
                left:        '50%', 
                top:        '50%'
            }).css({
                marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
                marginTop:    '-' + (t.outerHeight() / 2) + 'px'
            });
            if (absolute) {
                t.css({
                    marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                    marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
                });
            }
        });
    };
    jQuery("#login-box").center();
    // slide up/down login panel
    jQuery("#login, .login-top").click(function(){
        jQuery('body').append('<div id="overlay" />');
        jQuery('#overlay').fadeTo('fast', 0.3);
        jQuery("#login-box").stop().fadeIn();
    });
    jQuery("#login-close").click(function(){
        jQuery('#overlay').fadeOut();
        jQuery("#login-box").fadeOut();
    });			
}

//---//
function avio_lightbox(){	
    //basic lightbox
    jQuery().piroBox({
        my_speed: 300, //animation speed
        bg_alpha: 0.3, //background opacity
        slideShow : true, // true == slideshow on, false == slideshow off
        slideSpeed : 4, //slideshow
        close_all : '.piro_close, .piro_overlay' // add class .piro_overlay(with comma)if you want overlay click close piroBox
    });
			
    // fade the lightboxes when hoverd(adds an tip)
    jQuery(".pirobox, .pirobox_portfolio, .pirobox_gallery").hover(function(){
        jQuery(this).find("img").stop().fadeTo("fast",0.7);
        jQuery(this).append('<span class="lightbox-tip" ></span>');
    }, function(){
        jQuery(this).find("img").stop().fadeTo("fast",1.0);
        jQuery("span.lightbox-tip").fadeOut(200);
    });
			
    // removing the loader background
    // this willprevent the showing of the img when hoverd due the opacity of the images
    jQuery('div.gallery-box, a.blog-img, a.portfolio-img, .imgwrap-theme').hover(function() {
        jQuery(this).css({
            backgroundImage: "none"
        });	
    });
			
    // fading in the shadows
    // IE dont like fading stuff, so thsi has an IE fallback
    if(jQuery.browser.msie){
        jQuery(".shadow-140, .shadow-225, .shadow-240, .shadow-300, .shadow-460, .shadow-450, .shadow-620, .shadow-960").show(1);	 
    }else{
        jQuery(".shadow-140, .shadow-225, .shadow-240, .shadow-300, .shadow-460, .shadow-450, .shadow-620, .shadow-960").delay(1000).fadeIn(1000);	 
    }			 
}
//---//
function avio_tweets(tws, username){
    getTwitters('sidebar-tweets', {
        id: username, 
        clearContents: false, // leave the original message in place
        count: tws,
        timeout: 200,
        withFriends: true,
        ignoreReplies: false,
        newwindow: true,
        template: '<a href="http://twitter.com/%screen_name%">%user_screen_name%</a> said: "%text%" - <span>%time%</span>'

    });
}
//---//
function avio_scroll_top(){
    jQuery('#top').click(function() {
        jQuery('html, body').animate({
            scrollTop:0
        }, 'slow');
    });
}
//---//	
function avio_switch_view(){
    jQuery("a.switch_thumb").toggle(function(){
        jQuery(this).addClass("swap");
        jQuery("ul.display").fadeOut("fast", function() {
            jQuery(this).fadeIn("fast").removeClass("display").addClass("thumb_view");
        });
    }, function () {
        jQuery(this).removeClass("swap");
        jQuery("ul.thumb_view").fadeOut("fast", function() {
            jQuery(this).fadeIn("fast").addClass("display").removeClass("thumb_view");
        });
    }); 
}

