function show_team_member(id) {
    $j('.member-container').each(function(index) {
        if ($j(this).css('display') == 'block') {
            $j(this).fadeOut('fast', function() {
                var member_id = "member-" + id + "-content";
                $j('#' + member_id).fadeIn('fast', function() {
                });
            }); 
        }//end if
    });
}//end function

function show_comment_reply_form(id) { 
    $j('.blog-reply-window').each(function(index) {
        $j(this).hide();
    });

    $j('#reply-window-' + id).animate({height: 700}, 250, function() {
        $j("#reply-iframe-" + id).attr('src', "/immagine-australia/our-blog/post/comment/reply/" + id + "/");
    });
}//end function

function hide_comment_reply_form() { 
    $j('.blog-reply-window').each(function(index) {
        $j(this).animate({height: 0}, 250, function() {
            $j(this).hide();
        });
    });
}//end function

(function($){
    $.fn.extend({
 	    customStyle : function(options) {

	        if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)) {
        	    return this.each(function() {
			        var currentSelected = $(this).find(':selected');
			        $(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
			        var selectBoxSpan = $(this).next();
			        var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
			        var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			        selectBoxSpan.css({display:'inline-block'});
			        selectBoxSpanInner.css({width:selectBoxWidth + 50, display:'inline-block'});
			        var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			        $(this).height(selectBoxHeight).change(function() {
				        // selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
			            selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
				        // Thanks to Juarez Filho & PaddyMurphy
			        });
                    var selectBoxWidth = parseInt(selectBoxSpan.width() + 14);
     		        $(this).width(selectBoxWidth);
	            });
	        }
	    }
    });
})(jQuery);


var $j = jQuery.noConflict();
$j(document).ready(function() {

    $j(".portfolio_box img, .portfolio_box_slide img, .related_posts_box img, .sidebar img, .post_entry.blog img").hover(function() { 
        $j(this).animate({opacity: .7,left: '0px'}, "300"); 
    }, function() { 
        $j(this).animate({opacity: 1,left: '0px'}, "300"); 
    });

    $j(".toggle_container").hide(); 
    $j("h2.trigger").click(function(){$j(this).toggleClass("active").next().slideToggle("slow");});

    $j('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var $jtarget = $j(this.hash);
            $jtarget = $jtarget.length && $jtarget || $j('[name=' + this.hash.slice(1) +']');
            if ($jtarget.length) {
                var targetOffset = $jtarget.offset().top;
                $j('html,body').animate({scrollTop: targetOffset}, 900);
                return false;
            }
        }
    });

    $j("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});

    $j("ul.menu").superfish();
        
    var team_show_done = false;
    $j('.member-container').each(function(index) {
        $j(this).hide();
    });

    $j('.member-container').each(function(index) {
        if (!team_show_done) {
            $j(this).show();       
            team_show_done = true; 
        }//end if
    });

    $j(".member-team-container").click(function(e) {
        var id = $j(this).attr('id');  
        var member_id = id.replace('member-', '');
        show_team_member(member_id);
    })

    $j(".member-team-container-first").click(function(e) {
        var id = $j(this).attr('id');  
        var member_id = id.replace('member-', '');
        show_team_member(member_id);
    })

    $j(".comment-reply-link").click(function(e) {
        var id = $j(this).attr('id');  
        var comment_id = id.replace('comment-', '');
        show_comment_reply_form(comment_id);
    })

    $j(".filled").hover(function(e) {
        var data = $j(this).attr('data')
        var data_array = data.split('|');
        if (data_array.length > 0) {
            var hover_date = $j(this).html() + " " + data_array[0];
            var body = "<br>";
            for (x = 1; x < data_array.length; x++) {
                body += data_array[x] + "<br>";
            }
            $j('body').append("<div id='info-div'><b>" + hover_date + "</b>" + body + "</div>");
            $j('#info-div').css({ "left": e.pageX - 320 + "px", "top": e.pageY - 15 + "px" }).show();

        }
    }, function(e) {
        $j('#info-div').remove();
    });

    $j(".filled").click(function(e) {
        var data = $j(this).attr('class');
        var css = data.split(' '); 
        if (css.length >= 3) {
            slug = css[2];
            window.location.href = "/seminars/" + slug;
        }
    })

    $j(".open-new-window").click(function(e) {
        $j(this).attr('target', '_blank'); 
    })

    $j('a').each(function() {
        var a = new RegExp('/' + window.location.host + '/');
        if(!a.test(this.href)) {
            var id = $j(this).attr('id'); 
            if (id.substring(0, 7) != "comment") {
                $j(this).click(function(event) {
                    event.preventDefault();
                    event.stopPropagation();
                    window.open(this.href, '_blank');
                });
            }
        }
    });

});

// Cufon font
Cufon.replace('h1, h2, h3, h4, h5, h6', {hover: true});


