var contentsize = 0;
$( function(){
	
	$(".serviceslink").click( function(){
		$("#servicesbox").toggle();									   
   });
	
	
	$( '.share li.smaller' ).click( function(){
		if( contentsize <= -2 ){
			return false;
		}
		--contentsize;
		$( '.content > p ' ).each( function(){
			$( this ).css({
				fontSize: parseInt( $( this ).css( 'fontSize' ) ) - 1
			});
		});
	});
	$( '.share li.bigger' ).click( function(){
		if( contentsize >= 2 ){
			return false;
		}
		++contentsize;
		$( '.content > p ' ).each( function(){
			$( this ).css({
				fontSize: parseInt( $( this ).css( 'fontSize' ) ) + 1
			});
		});
	});
	
	// MAIN CATEGORY - TOP LINK TABS
	$( '.title .menu ul li' ).click( function(){
		if( $( this ).hasClass( 'selected' ) ){
			return false;
		}
		var width = $( '.selectmenu .top ul.left' ).hide().filter( '#' + $( this ).html() ).show().width();
		var left = $( this ).position().left + $( this ).width() / 2 - width / 2;
		if( left < 10 ){
			left = 10;
		}
		if( width > 670 ){
			left = 10;
		}
		else if( left + width > 670 ){
			left = 670 - width;
		}
		$( '.selectmenu .top ul.left:visible' ).css( 'marginLeft', left );
		$( '.title .menu ul li' ).removeClass( 'selected' );
		$( this ).addClass( 'selected' );
	});
	
	$( '#popularTabs li').click( function(){
		if( $( this ).hasClass( 'selected' ) ) {
			return false;
		}
		$( '#popularTabs li' ).removeClass( 'selected' );
		$( this ).addClass( 'selected' );
		
		$( '#popularPod .innerbox ol' ).hide();
		
		$( '#popularPod .innerbox ol#' + $( this ).attr('id') + '-box' ).show();
		
    });
	
	
	// drop down menu initialize
/*	var currentlist = $( '.top .submenucategories ul:visible' );
	$( '.top .submenucategories ul' ).each( function(){
		var size = 0;
		var index = 0;
		$( this ).show();
		$( this ).children( 'li' ).each( function( i ){
			size += $( this ).outerWidth( true );
			if( size < 600 ){
				index = i;
			}
			else{
				return false;
			}
		});
		if( index != $( this ).children().length - 1 ){
			$( document.createElement( 'li' ) ).addClass( 'dropdown' ).html( '<span>dd</span><ul></ul>' ).insertAfter( '#' + $( this ).attr( 'id' ) + ' li:nth-child(' + ( index + 1 ) + ')' );
			$( this ).children( 'li.dropdown' ).nextAll().appendTo( '#' + $( this ).attr( 'id' ) + ' li.dropdown ul' );
			$( this ).find( 'li.dropdown > span' ).click( function(){
				$( this ).next().toggle();
			});
		}
		$( this ).hide();
	});*/
    $( '.dropdown ul' ).hover( function(){
        $( this ).attr( 'over', 'true' );
    }, function(){
        $( this ).attr( 'over', 'false' );
    });
    $( '.dropdown > a' ).hover( function(){
        $( this ).siblings( 'ul' ).show();
    }, function(){
        var id = $( this ).parent().attr( 'id' );
        var rec = function(){
            if( $( '#' + id ).children( 'ul' ).attr( 'over' ) == 'true' ){
                setTimeout( rec, 300 );
                return true;
            }
            $( '#' + id ).children( 'ul' ).hide();
        }
        setTimeout( rec, 300 );
    });
	//currentlist.show();
});