//var $ = jQuery.noConflict();

	
$(document).ready(function(){
	// Lightbox öffnenm, wenn man von Google kommt
	if(window.location.search.indexOf("openLightBox") != -1) {
//		TopUp.display("http://www.marap.at",'');
//		TopUp.display('http://www.marap.at', 'width = 800, height = 400, type = iframe, title = Google search, layout = quicklook');
//		TopUp.display ('http://google.com', {title:'google search',layout:'dashboard',type:'iframe',width:800,height:400,modal:0});
	}
	
	// Setze TopUp Bildpfad
	TopUp.images_path  = "http://www.pearlsofsamarkand.com/fileadmin/templates/js/images/top_up/";
	TopUp.enableFastMode = true;
	TopUp.addPresets({
		".i_rohstoffe A": {
			type: "iframe",
			width: 520,
			height: 520,
			resizable: 0,
			overlayClose: 1,
			shaded: 1,
			effect: "transform",
			layout: "flatlook"
		}
		/*
		".i_galerie A": {
			type: "image",
			resizable: 0,
			overlayClose: 1,
			shaded: 1,
			effect: "transform",
			layout: "flatlook",
			group: 1
		}
		*/
	});	
	// Sprachmenü
	//$("#lang_button").hide();
	//$(".s_sprache").width(37);
	$('.s_kopfbox').prepend('<div class="s_schrift"><span class="font_normal" onclick="setActiveStyleSheet(\'font100%\'); return false;" id="f1">A</span><span class="font_gross" onclick="setActiveStyleSheet(\'font110%\'); return false;" id="f2">A</span></div>');
	
	// Angebote Slider ALT !!!
	$('.sh_angebote').css("display","block");
	$('.sh_angebote_m').cycle({ 
		fx:       'fade', 
		speed:    500, 
		timeout:  6000,
		next:     '.sh_angebote_r A', 
		prev:     '.sh_angebote_l A' 
	});
	
	// Angebote Slider
	$('.i_angebote').css("display","block");
	$('.i_angebote_m').cycle({ 
		fx:       'fade', 
		speed:    500, 
		timeout:  6000,
		next:     '.i_angebote_r A', 
		prev:     '.i_angebote_l A' 
	});
	
});

function wp_gotourl (siteurl) {
	basehref = this.location.href;
	endpos = basehref.indexOf("/", 10);
	baseurl = basehref.substring(0,endpos);
	location.href = baseurl + '/' + document.getElementById('url' + siteurl).value;
}

// Styleswitcher Start
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")) {
	  if(a.getAttribute("title").indexOf("font") != -1) {
	    a.disabled = true;
        if(a.getAttribute("title") == title) a.disabled = false;
	  }
    }
  }
}

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) {
	  if (a.getAttribute("title").indexOf("font") != -1) 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")
       ) {
	  if(a.getAttribute("title").indexOf("font") != -1) 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;
}

// Styleswitcher Ende

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

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

function degetPreferredStyleSheet() {
  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")
       ) {
	  if(a.getAttribute("title").indexOf("kont") != -1) return a.getAttribute("title");
	}
  }
  return null;
}

function decreateCookie(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 dereadCookie(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);
  var decookie = dereadCookie("destyle");
  var detitle = decookie ? decookie : degetPreferredStyleSheet();
  desetActiveStyleSheet(detitle);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title );
  var detitle = degetActiveStyleSheet();
  decreateCookie("destyle", detitle );
}

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

var decookie = dereadCookie("destyle");
var detitle = decookie ? decookie : degetPreferredStyleSheet();
desetActiveStyleSheet(detitle);
// Designswitcher Ende

