

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  createCookie("style", title, 365);
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

function showPrint() {
  FOTOMOTO.API.showWindow(FOTOMOTO.API.PRINT, "mainPhoto");
}

function showPrint2() {
  FOTOMOTO.API.showWindow(FOTOMOTO.API.PRINT, "mainPhoto2");
}

function showPrint3() {
  FOTOMOTO.API.showWindow(FOTOMOTO.API.PRINT, "mainPhoto3");
}

// VIEWPORT SETTINGS

if (navigator.userAgent.indexOf('iPhone') != -1) {
	document.write('<meta name="viewport" content="width=480px, maximum-scale=1.0, user-scalable=0">');
}
if (navigator.userAgent.indexOf('iPad') != -1) {
	document.write('<meta name="viewport" content="width=1024px, maximum-scale=1.0, user-scalable=0">');
}
if (navigator.userAgent.indexOf('Android') != -1) {
}


function showIconTop() {
  
}
function hideIconTop() {
  
}

$(document).ready(function() {
	// hide URL bar on mobile, note: only works on 'Go' not on refresh
	window.scrollTo(0,1);
	
	$('.pGrid div a').hover(
		function(){
			$(this).parent().stop().animate({ 
				backgroundColor: "#006699",
				color: "#ffffff"
				}, 250);
			$(this).stop().animate({ 
				backgroundColor: "#006699",
				color: "#ffffff"
				}, 250);
			},
		function(){
			$(this).stop().animate({ 
				backgroundColor: "#d0d0d0",
				color: "#006699"
				}, 250);
			$(this).parent().stop().animate({ 
				backgroundColor: "#d0d0d0",
				color: "#000000"
				}, 250);
			});
		
	// fade in #back-top
	$(function () {
		$(window).scroll(function () {
				if ($(this).scrollTop() > 50) {
					$('#iconTop').delay(50).animate({
						opacity: 1
						}, 250);
				} else {
					$('#iconTop').delay(50).animate({
						opacity: 0
						}, 250);
				}
		});

		// scroll body to 0px on click
		$('#iconTop a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});
	
	
	
	 if ( $.browser.msie ){
		if($.browser.version < '9.0') {
			$('.pContainer').css('backgroundColor','#e8e8e8');
		}
	 }
	 else if ( $.browser.webkit ) {
	 }
	 else if ( $.browser.mozilla ) {
	 }
	 else if ( $.browser.opera ) {
	 }
	
});
