var windowH, windowW, top, bottom, daxlineLight;

$(document).ready(function(){

	var url = $(document).url();
	var path = url.attr('path');
	$('#nav a[href="' + path + '"]').addClass('current');
	
	$('body:not(.galleries) #selectable li .photo img').load(function(){
		var imgHeight = $(this).height();
		var imgWidth = $(this).width();
		if (imgWidth > imgHeight) {
			$(this).attr('height',150).css('margin-top',-75).css('margin-left',-$(this).width()/2);
		} else {
			$(this).attr('width',150).css('margin-left',-75).css('margin-top',-$(this).height()/2);
		};
		$(this).animate({ opacity: 1 }, 0 );
	});	
	
	setInterval(function() {
		$('.errorlist').fadeTo(500,0.5).delay(500).fadeTo(500,1)
    }, 2000);
    
	// Trigger Selectable
	$('body.selectable #content').selectable({
		filter: 'li:not(.noselect)',
		cancel: 'a, .zoom, .styled, input'
	});
	
	// Notice Closer
	$('.closeNotice').click(function(){
		$(this).parent().fadeOut();
	});
	
	// Date picker for search box
	$('.datePicker').datepicker({showOn: 'button', buttonImage: '/pmt_media/img/icon-calendar.gif', buttonImageOnly: true});
	
	// Toggle Search Fields
	var searchPadding = $('.searchPadding').length;
	$('a.search').toggle(function(){
		if (searchPadding == 0){
			$('#search-bar').fadeIn('fast');
			$('.container').animate({
		        paddingTop: "55px"
		      }, 1000 );
	    } else {
	    	$('#search-bar').fadeOut('fast');
			$('.container').animate({
		        paddingTop: "20px"
		      }, 1000 );
	    };
	},function(){
		if (searchPadding == 0){
			$('#search-bar').fadeOut('fast');
			$('.container').animate({
		        paddingTop: "20px"
		      }, 1000 );
	    } else {
	    	$('#search-bar').fadeIn('fast');
			$('.container').animate({
		        paddingTop: "55px"
		      }, 1000 );
	    };
	});
	
	// Fixing the subnavigation bar to top top
	var top = $('.fixer').offset().top - parseFloat($('.fixer').css('marginTop').replace(/auto/, 0));
	$(window).scroll(function (event) {
		sticky();	
	});
	  
	function sticky(){
		// what the y position of the scroll is
	    var y = $(this).scrollTop();
	  
	    // whether that's below the form
	    if (y >= top) {
	      // if so, ad the fixed class
	      $('.fixer').addClass('fixed');
	    } else {
	      // otherwise remove it
	      $('.fixer').removeClass('fixed');
	    };	
	};




	
	if($('.tabs').length){
	    // Custom tabbing panel for settings and account
	    $('.tabs #sub-left li a').click(function(){
	    	var what = $(this).attr('href');
	    	$('.tabs .panel').hide();
	    	$('.tabs #sub-left li a').removeClass('current');
	    	$(this).addClass('current');
	    	$(what).show();
	    	sifr();
	    	sticky();
	    	$(document).url().attr('hash',what.replace('#',''))
	    	return false;
	    });
	    
	    var hash = $(document).url().attr('hash')
	    $('.tabs .panel').hide();
	    
	    if(hash){
	    	$(".tabs #sub-left li a[href='#"+hash+"']").click();
    	}else{
    		$(".tabs #sub-left li a:eq(0)").click();
    	};
    };

    // Custom tabbing panel for blurbs and design
    $('.tab-info').hide();
    $('.tab-col li').click(function(){
    	var what = $(this).attr('rel');
    	$('.tab-info').hide();
    	$('.tab-col li').removeClass('current');
    	$(this).addClass('current');
    	$(what).show();
    	sifr();
    	return false;
    });
    $('.tab-col li:eq(0)').click();

	// Image upload box    
	$('a.upload').click(function() {
		window.open($(this).attr('href'), 'upload_photoz', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=430,height=530,left=100,top=100');	
		return false;
	});
   
  

   	sifr();
});

function footerSizer() {
	var windowW = $(window).width();
	$('#pager, #footer, #sub-nav').css('width',windowW);
};

// Clear form function
function clearForm() {
  $('input.hidden:checked').each(function() {
  	this.checked = false;
  });
};

function sifr() {
	sIFR.activate(daxlineLight);

	sIFR.replace(daxlineLight, {
	selector: 'h2.styled',
	wmode: 'transparent',
	css: [  
		'.sIFR-root { color: #ed2d00; }'
		,'a { color: #ed2d00; }'  
		,'a:link { color: #ed2d00; }'  
		,'a:hover { color: #ed2d00; }'  
	]
	});
	
	sIFR.replace(daxlineLight, {
	selector: '.sub-col h2.styled',
	wmode: 'transparent',
	css: [  
		'.sIFR-root { color: #ed2d00; }'
		,'a { color: #ed2d00; }'  
		,'a:link { color: #ed2d00; }'  
		,'a:hover { color: #ed2d00; }'  
	]
	});
	
	sIFR.replace(daxlineLight, {
	selector: 'h3.styled',
	wmode: 'transparent',
	css: [  
		'.sIFR-root { color: #555555; }'
		,'a { color: #555555; }'  
		,'a:link { color: #555555; }'  
		,'a:hover { color: #555555; }'  
	]
	});
};

