
function rem_active_bw(){
    $('#portfolio li.active').removeClass('active');
    $('#portfolio li').not(param+'.bw').css('display','none');
    $('#portfolio li'+param+'.bw').addClass('active');
    clearTimeout(d);
    clearTimeout(t);
};
function rem_active_color(){
    $('#portfolio li.active').removeClass('active');
    $('#portfolio li').not(param+'.color').css('display','none');
    $('#portfolio li'+param+'.color').addClass('active');
    clearTimeout(d);
    clearTimeout(t);
};
function sub_nav_fadeout(){
    $('.sub_menu').fadeOut('slow');   
    $('.nav').css('display','none');  
    $('#content').children().css("display", 'none');
    $('#content .title').css("display",'block');
};
function if_color_or_bw(){
    if ($('#portfolio li'+param).hasClass('bw'||'color')){
    $('#portfolio li'+param).addClass('active');
    $('#portfolio li').not(param).removeClass('active').css('display','none');
    $(s+' a').removeClass('active');
    $('.sub_menu span').not(s).css('display','none');
    $(s).fadeIn('slow');
    $('.nav').fadeOut('slow'); 
    t = setTimeout('$.pause()', 3001);
    }
    else {
    $('.sub_menu span').css('display','none');
    $('.nav').fadeIn('slow');
    $('#portfolio li'+param).addClass('active');
    $('#portfolio li').not(param).removeClass('active').css('display','none');
    }
};
function slide_nav(){
    $('#slide_nav li:gt('+(elem-element-1)+')').css('display', 'block');
    $('#slide_nav li:lt('+(elem-element)+')').css('display', 'none');    
};
function menu_pause(){
     $('#portfolio li').css('display','none'); 
};
function margin_up(){
    if (parseInt(_margin_top)>=(_max_margin)){
    _margin_top = parseInt(_margin_top)-4;
    $(container).css('marginTop',_margin_top+'px');
    }
};
function margin_down(){
    if (parseInt(_margin_top)<=0){
    _margin_top = parseInt(_margin_top)+4;
    $(container).css('marginTop',_margin_top+'px');
    }
};
function play_slide(){ 
    if ($('.nav:hidden')){
      $.pause()
      }
};

var interval;
var _cont_height
var _max_margin;
var _margin_top;
var isPlay;

window.onload = function() {


$('#preloader').css("display", 'none');
$('#content,#menu').fadeIn('slow');
 
$('.music').toggle(
      function () {
        soundManager.muteAll();
      },
      function () {
        soundManager.unmuteAll();
      }
    );

$('.music').click(function(){
  if ($(this).hasClass('on')){  
    $(this).removeClass('on');
    }
  else 
  $(this).addClass('on');
});

/* images resize script */

  $('#portfolio li img').each(function(){
  
  h = $(this).height();
  w = $(this).width();
  _wsp = h/w;
  _h = 400*_wsp;
  _w = 400/_wsp;
  _marH = (400-_h)/2;
  _marW = (400-_w)/2;
  
    if (parseInt(_w)>=400 && parseInt(_h)<=400){
    $(this).css('width', 400+'px');
    $(this).css('margin-top',_marH+'px');    
  	} 	
    else if (parseInt(_h)>=400 && parseInt(_w)<=400) {
    $(this).css('height', 400+'px');
    $(this).css('margin-left',_marW+'px');       
  	};
       
  });

/* ============ nav script ============== */

          elem = $('#slide_nav li').length;
          elem_one = $('#portfolio li.one').length;
          elem_two = $('#portfolio li.two').length;
          elem_three = $('#portfolio li.three').length;
          elem_four = $('#portfolio li.four').length;
          
                    
          function sliderfn(){
           if (parseInt(sliderh)>400){
            $(slider).css("display",'block');
            $(container).css("width","380px");
            $(container).css("float","left");            
           }
          };
          
  $('.btn_down').mousedown(function(){
   interval = setInterval('margin_up()', 1); 
  });  
  $('.btn_down').mouseup(function(){
   interval = clearInterval(interval); 
  });
  
  $('.btn_up').mousedown(function(){
   interval = setInterval('margin_down()', 1);
  });
  $('.btn_up').mouseup(function(){
   interval = clearInterval(interval);
  });         

/* ============  menu script ============ */
  
  $('#menu a').click(function(){
    $(this).siblings().removeClass('active');
    $(this).addClass('active');  
  });
//portfolio  
  $('.menu_one').click(function(){
    $('#content').children().css("display", 'none');
    $('#slideshow').fadeIn('slow');
    $('#content .title').css("display",'block');
    $('.sub_menu').fadeIn('slow');
    $('.nav').fadeOut('slow'); 
    $('#portfolio li').addClass('active');
    $('.sub_menu a').removeClass('active')
    $('.s_one,.s_two,.s_three,.s_four').fadeOut('slow');
      //soundManager.stopAll();
      //soundManager.play('mainSound');
     $.first();
     d = setTimeout('$.pause()', 3001);            
return false;
  });
//two
  $('.menu_two').click(function(){
    menu_pause(); 
    sub_nav_fadeout(); 
    $('#about').fadeIn('slow');    
    sliderh = $('.slide_one').height();  
    container = $('.slide_one');
    slider =  $('#about .slider');
    sliderfn();
    _margin_top = $(container).css('marginTop');    
    _cont_height = $(container).height();
    _max_margin = (-(parseInt(_cont_height)-400));                    
return false; 
  });
//three
  $('.menu_three').click(function(){
    menu_pause(); 
    sub_nav_fadeout(); 
    $('#contact').fadeIn('slow');     
    sliderh = $('.slide_two').height();
    container = $('.slide_two');
    slider =  $('#contact .slider');
    sliderfn();
    _margin_top = $(container).css('marginTop');  
    _cont_height = $(container).css('height');
    _max_margin = (-(parseInt(_cont_height)-400));    
return false;
  });
//four
  $('.menu_four').click(function(){
    menu_pause(); 
    sub_nav_fadeout();
    $('menu_four').fadeIn('slow');    
    sliderh = $('.slide_three').height();
    container = $('.slide_three');
    slider =  $('menu_four .slider');
    sliderfn();
    _margin_top = $(container).css('marginTop');  
    _cont_height = $(container).css('height');
    _max_margin = $(-(parseInt(_cont_height)-400));            
return false;
  });

/* =========== sub menu script ============ */

// sub one script
  $('.sub_one').click(function(){
    param = '.one';    
    s = ('.s_one');
    if_color_or_bw();  
    element = elem_one;
    slide_nav();        
    $.first(); 
    
    //soundManager.stopAll();
    //soundManager.play('oneSound');  
return false; 
  });

// sub two script  
  $('.sub_two').click(function(){
    param = '.two';
    s = ('.s_two');         
    if_color_or_bw();      
    element = elem_two;
    slide_nav();       
    $.first();     
      
    //soundManager.stopAll();
    //soundManager.play('twoSound');    
return false;
  });

//sub three script  
  $('.sub_three').click(function(){
    param = '.three';
    s = ('.s_three');
    if_color_or_bw();        
    element = elem_three;
    slide_nav();       
    $.first();     
         
    //soundManager.stop('mainSound','twoSound','twoSound','fourSound');
    //soundManager.play('threeSound');    
return false;
  });

//sub four script  
  $('.sub_four').click(function(){
    param = '.four';
    s = ('.s_four');
    if_color_or_bw();    
    element = elem_four;
    slide_nav();          
    $.first();     
          
    //soundManager.stop('mainSound','twoSound','threeSound','threeSound');
    //soundManager.play('fourSound');    
return false;
  });
   
/* ============= b&w / color script =============== */

$('p.sub_menu a.bw').click(function (){
  $('.nav').fadeIn('slow'); 	
return false;
});

$('p.sub_menu a.color').click(function (){
  $('.nav').fadeIn('slow');
return false;
});
  
      elem_one_color = $('#portfolio li.one.color').length;
      elem_one_bw = $('#portfolio li.one.bw').length;
      elem_two_color = $('#portfolio li.two.color').length;
      elem_two_bw = $('#portfolio li.two.bw').length;
//one       
  $('p.sub_menu span.s_one a.bw').click(function (){
    param = '.one';
    $('#slide_nav li:gt('+(elem-elem_one-1+elem_one_color)+')').css('display', 'block');
    $('#slide_nav li:lt('+(elem-elem_one+elem_one_color)+')').css('display', 'none');
    rem_active_bw();    
    $.first();
return false;
  });
  
  $('p.sub_menu span.s_one a.color').click(function (){
    param = '.one';
    $('#slide_nav li:gt('+(elem-elem_one-1+elem_one_bw)+')').css('display', 'block');
    $('#slide_nav li:lt('+(elem-elem_one+elem_one_bw)+')').css('display', 'none');
    rem_active_color();  
    $.first();
return false;
  });
//two
  $('p.sub_menu span.s_two a.bw').click(function (){
    param = '.two';
    $('#slide_nav li:gt('+(elem-elem_two-1+elem_two_color)+')').css('display', 'block');
    $('#slide_nav li:lt('+(elem-elem_two+elem_two_color)+')').css('display', 'none');
    rem_active_bw();  
    $.first();
return false;
  });
  
  $('p.sub_menu span.s_two a.color').click(function (){
  param = '.two';
    $('#slide_nav li:gt('+(elem-elem_two-1+elem_two_bw)+')').css('display', 'block');
    $('#slide_nav li:lt('+(elem-elem_two+elem_two_bw)+')').css('display', 'none');
    rem_active_color();  
    $.first();
return false;
  });
//three
  $('p.sub_menu span.s_three a.bw').click(function (){
    param = '.three';
    $('#slide_nav li:gt('+(elem-elem_three-1+elem_three_color)+')').css('display', 'block');
    $('#slide_nav li:lt('+(elem-elem_three+elem_three_color)+')').css('display', 'none');
    rem_active_bw();    
    $.first();
return false;
  });
  
  $('p.sub_menu span.s_three a.color').click(function (){
    param = '.three';
    $('#slide_nav li:gt('+(elem-elem_three-1+elem_three_bw)+')').css('display', 'block');
    $('#slide_nav li:lt('+(elem-elem_three+elem_three_bw)+')').css('display', 'none');
    rem_active_color();  
    $.first();
return false;
  });
//four
  $('p.sub_menu span.s_four a.bw').click(function (){
    param = '.four';
    $('#slide_nav li:gt('+(elem-elem_four-1+elem_four_color)+')').css('display', 'block');
    $('#slide_nav li:lt('+(elem-elem_four+elem_four_color)+')').css('display', 'none');
    rem_active_bw();    
    $.first();
return false;
  });
  
  $('p.sub_menu span.s_four a.color').click(function (){
    param = '.four';
    $('#slide_nav li:gt('+(elem-elem_four-1+elem_four_bw)+')').css('display', 'block');
    $('#slide_nav li:lt('+(elem-elem_four+elem_four_bw)+')').css('display', 'none');
    rem_active_color();  
    $.first();
return false;
  });

/* ============= innerfade config script ============= */



   
        $('ul#portfolio').innerfade({
        speed: 800,   //speed: Fading-/Sliding-Speed in milliseconds or keywords (slow, normal or fast) (Default: 'normal')
        timeout: 5000,   //timeout: Time between the fades in milliseconds (Default: '2000'), 
        type: 'sequence',
        containerheight: 	'400px',
        slide_timer_on: 	'yes',
        slide_ui_parent: 	'portfolio',
        children:         ' li.active',
       	pause_button_id: 	'pause_button',
       	slide_nav_id:		'slide_nav'       
    	});
      
    	
    	$.setOptionsButtonEvent();
        
   		$("#pause_button").click(function() {
   			$.pause();
        });
        
      $("#next_button").click(function() {
    		$.next();
        });
        
      $("#prev_button").click(function() {
        	$.prev();
        });
        
    	$("#first_button").click(function() {
        	$.first();
        });
        
    	$("#last_button").click(function() {
        	$.last();
        });

//$.playnew();
};


	







