$(function(){
	// theme switcher
	$('a#designerswitch').click(function(e) {
		$('body').removeClass('coder').addClass('designer');
		$('a#coderswitch').removeClass('active');
		$(this).addClass('active');
		e.preventDefault();
	});
	$('a#coderswitch').click(function(e) {
		$('body').removeClass('designer').addClass('coder');
		$('a#designerswitch').removeClass('active');
		$(this).addClass('active');
		e.preventDefault();
	});
	// window buttons
	$('a#close').click(function(e) {
		$('#app').fadeOut('fast');
		$('#oops').delay(500).fadeIn('medium');
		$('body').addClass('oops');
		e.preventDefault();
	});
	$('a#minimize').click(function(e) {
		$('body').removeClass().addClass('minimized');
		e.preventDefault();
	});
	$('a#maximize').click(function(e) {
		$('body').removeClass('minimized').addClass('maximized designer');
		e.preventDefault();
	});
	
	// reinvented dropdown
	 createDropDown();
	            
    $(".dropdown dt a").click(function(e) {
        $(".dropdown dd ul").toggle();
        e.preventDefault();
    });

    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if (! $clicked.parents().hasClass("dropdown"))
            $(".dropdown dd ul").hide();
    });
                
    $(".dropdown dd ul li a").click(function(e) {
        var text = $(this).html();
        $(".dropdown dt a").html(text);
        $(".dropdown dd ul").hide();
        
        e.preventDefault();
        
        var source = $("#source");
        source.val($(this).find("span.value").html())
    });
    
	
	// filtering portfolio
	$(".dropdown dd ul a").click(function() { 
        var selection = $(this).children('span').html(); 
 
        if (selection == "all") 
        { 
            //show all items 
            $("#workspace figure").show();
        } 
        else 
        { 
            $("#workspace figure").hide(); 
            $("#workspace figure."+selection).show(); 
        } 
	 });  
	 
	 // z-index fixer 
	 $('header').css( 'z-index', 200);
	 $('#workspace').css('z-index', 1);    
});


// reinvented dropdowns function
function createDropDown(){
    var source = $("#filter");
    var selected = source.find("option[selected]");
    var options = $("option", source);
    
    $("#portfoliofilter .buttonwrapper").append('<dl id="target" class="dropdown"></dl>');
    $("#target").append('<dt><a href="#">' + selected.text() + 
        '<span class="value">' + selected.val() + 
        '</span></a></dt>');
    $("#target").append('<dd><ul></ul></dd>');

    options.each(function(){
        $("#target dd ul").append('<li><a href="#">' + 
            $(this).text() + '<span class="value">' + 
            $(this).val() + '</span></a></li>');
    });
}



