var $jQ = jQuery.noConflict();

function pageload(hash) {
	if(hash) {
		hash = hash.replace(/^.*\//, '');
		$jQ('.tabs').tabs('select', hash);
	} else {
		$jQ('.tabs').tabs('select', 0);
	}
}

/* Global
------------------------------------------------------- */
$jQ(document).ready(function() {

	if ($jQ('.tabs').length) {
		$jQ.historyInit(pageload);
	};
	//Adjust top spacing for header images equal to 260px height 
	if ($jQ('.small img.product').height() == 260) {
		$jQ('.small').css('top', -8);
		if (window.console && window.console.log) {
			window.console.log('top margin of header image adjusted');
		};
	};
	if (window.console && window.console.log) {
		window.console.log('header image height ', $jQ('.small img.product').height());
	};
	// Fixes aliment of H1, H2 and paragraphs on detail pages
	if ($jQ('.wide #product h1' && '.wide #product h2').length > 0) {
		var getH1Height = $jQ('.wide #product h1').height();
		var getH2Height = $jQ('.wide #product h2').height();	
		$jQ('.wide #product h2').css('top', getH1Height + 80);
		$jQ('.wide #product .description').css('top', getH1Height + getH2Height + 94);
	}
	else if ($jQ('.wide #product h1' || !'.wide #product h2').length > 0) {
		var getH1Height = $jQ('.wide #product h1').height();	
		$jQ('.wide #product .description').css('top', getH1Height + 79);
	};

	if ($jQ('.wide.kodak_9000 #product h1').length) {  
	    var getH1Height = $jQ('.wide.kodak_9000 #product h1').height();
		var getH2Height = $jQ('.wide.kodak_9000 #product h2').height();	
		$jQ('.wide.kodak_9000 #product h2').css('top', getH1Height + 89);
		$jQ('.wide.kodak_9000 #product .description').css('top', getH1Height + getH2Height + 94);   
	};

	if ($jQ('ul.tabs').length) {  	
		var $jQtabs = $jQ('ul.tabs').tabs();			
		$jQ('#quickfeatures a').click(function() {
		    $jQtabs.tabs('select', 0);
			$jQ('html, body').animate({ scrollTop: $jQ('.tabs').offset().top }, 1500, 'easeOutQuad');
		    return false;
		});
	};
	// For product detail pages. Adjusts for 1 or 2 boxes.
	if ($jQ('.splitcolumn').length > 0) {
		var getWidth = $jQ('.splitcolumn .right').width();
		var offSet = 80;
		$jQ('.splitcolumn .left').css({'width' : 960 - offSet - getWidth, 'padding-right' : '40px'});
	};
	
	if ($jQ('.tabs').length) {  
		//initiates tabs
		$jQ("ul.tabs").tabs();
	};
	
	if ($jQ('.tabs').length) {  
		//Previous/next buttons for tabs area
		$jQ('ul.tab_nav .next').click(function() {
			var $jQtabs = $jQ('ul.tabs').tabs();
			var selected = $jQtabs.data('selected.tabs');					
			$jQtabs.tabs('select', selected + 1);
			return false;
		});
		$jQ('ul.tab_nav .previous').click(function() {
			var $jQtabs = $jQ('ul.tabs').tabs();
			var selected = $jQtabs.data('selected.tabs');					
			$jQtabs.tabs('select', selected - 1);	
			return false;
		});
	};
	
	if ($jQ('#topnav').length) {
		var selectWidth = $jQ('#country').width();
		var topnavWidth = $jQ('#topnav ul').width();
		$jQ('#topnav').css({'width': (selectWidth + topnavWidth + 30 )});
	};

	if ($jQ('#breadcrumb').length) {
		$jQ('#nav').css({'bottom': 36});
		$jQ('#header').css({'height': 140});
	};

	//Removes border-bottom on last link in subnav
	if ($jQ('#subnav li:last a').length)
		$jQ('#subnav li:last a').css('border-bottom', 'none');
	
	if ($jQ('#productimage').length) {		
		$jQ('#imageswap a').preload();
		//product image setup
		$jQ('#imageswap a:first').attr('href', function(){
			var altName = $jQ(this).attr('title');
			$jQ('#productimage.slideshow').append('<img src="'+ this +'" alt="'+ altName +'" class="product" />');
			$jQ('img.product').fadeIn(1000);
		});
		$jQ('#imageswap a:first').addClass('selected');	
		//swaps product image
		$jQ('#imageswap a').click(function(){
			$jQ('#imageswap a').removeClass('selected');
			$jQ(this).addClass('selected');
			var imgSrc = $jQ(this).attr('href');
			$jQ('img.product').fadeOut(500, function() {
				$jQ(this).attr('src', imgSrc).fadeIn(1000);
			});	
			return false;
		});
	};
	
	$jQ('.enewsletter .threecolumn .leftcolumn .entry:last').css({'border': 'none'});
	
	if ($jQ('#request').length || $jQ('#request_demo').length) {
		//Request form pop out
	    $jQ('#request, #request_demo').each(function () {
	        var distance = -10;
	        var time = 250;
	        var trigger = $jQ('.trigger', this);
	        var info = $jQ('.popout', this).css('opacity', 0);
			var beingShown = false;
	        var shown = false;

			$jQ([trigger.get(0), info.get(0)]).click(function () {
	            if (beingShown || shown) {
	                // don't trigger the animation again
	                return false;
	            } else {
	                // reset position of info box
	                beingShown = true;

	                info.css({
	                    top: 127,
						position: 'absolute',
	                    display: 'block'
	                }).animate({
	                    top: '-=' + distance + 'px',
	                    opacity: 1
	                }, time, 'swing', function() {
	                    beingShown = false;
	                    shown = true;
	                });
					// shows form
					$jQ('#requestform').show();
	            }
	            return false;
	        });
			$jQ('.close a').click(
				function () {
			        	info.animate({
	                      top: '-=' + distance + 'px',
	                      opacity: 0
	                  }, time, 'swing', function () {
	                      shown = false;
	                      info.css('display', 'none');
	                  });
	              return false;
			      }			
			);
			$jQ('.close a').click(function () {	
				$jQ('#message').hide();	
			}
			);
	    });
		function switchText()
		{
			if ($jQ(this).val() == $jQ(this).attr('title'))
				$jQ(this).val('').removeClass('inputText');
			else if ($jQ.trim($jQ(this).val()) == '')
				$jQ(this).addClass('inputText').val($jQ(this).attr('title'));
		}

		$jQ('input[type=text][title!=""]').each(function() {
			if ($jQ.trim($jQ(this).val()) == '') $jQ(this).val($jQ(this).attr('title'));
			if ($jQ(this).val() == $jQ(this).attr('title')) $jQ(this).addClass('inputText');
		}).focus(switchText).blur(switchText);

		$jQ('form').submit(function() {
			$jQ(this).find('input[type=text][title!=""]').each(function() {
				if ($jQ(this).val() == $jQ(this).attr('title')) $jQ(this).val('');
			});
		});
		if (window.console && window.console.log) {
			window.console.log('document ready loaded');
		};
	};
});

/*
CSS Browser Selector v0.3.1
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);


