$(document).ready(function(){

if ((screen.width==1024) && (screen.height==768)) {
}
if ((screen.width>=1280) && (screen.height>=800)) {
	$("#wrapper").addClass("resoover1280x800");
}
if ((screen.width>=1920) && (screen.height>=1080)) {
	$("#wrapper").addClass("reso1920x1080").removeClass("resoover1280x800");
}
else if ((screen.width<1024) && (screen.height<768)) {
	$("#wrapper").addClass("res800x600");
}

// SHOW AND HIDE ProductTitle
// Hide all span
/*$("span.product-title").hide();
// FadeIn
$(".product-images a").mouseover(function(){
  $(this).next("span").addClass("t-acitve");
  return false;
});
// FadeOut
$(".product-images a").mouseout(function(){
  $(this).next("span").fadeOut(100);
  $(this).next("span").removeClass("t-acitve");
  return false;
});*/

// SHOW AND HIDE Press Releases
// Hide all span
$("div.press-text").hide().addClass('hidden');
$("#sliderpress ul li:nth-child(1) .press div.press-text:first").show();
$("#sliderpress ul li:nth-child(1) div.press:first .press-image img").addClass('active');
// FadeIn
$(".press").click(function(){
  if ($(this).find("div.press-text").hasClass('hidden')){
	  //remove the old ones
	  $("div.press-text").addClass('hidden').hide();
	  $(".press-image img").removeClass('active');
	  
	  $(this).find("div.press-text").removeClass('hidden');
	  $(this).find("div.press-text").fadeIn(100);
	  $(this).find(".press-image img").addClass('active');
	  return false;
  }
  else {
	$(this).next("div.press-text").fadeOut(100);
  }
});
/*// FadeOut
$(".press").mouseout(function(){
  $(this).next("div.press-text").fadeOut(100);
  return false;
});*/

$("#slider1000").easySlider({
    pause: 6000,
		auto: false,
		continuous: true,
		prevText: '',
		nextText: '',
		nextId: "slider1000next",
		prevId: "slider1000prev",
		autoAdjust:	true
	});

	$("#slider2000").easySlider({
	  pause: 4000,
		auto: false,
		continuous: true,
		prevText: '',
		nextText: '',
		nextId: "slider2000next",
		prevId: "slider2000prev",
		autoAdjust:	true
	});
	
	var firstObj = $("#slider1000 ul li:first-child").next();
	var secObj = $("#slider2000 ul li:first-child").next();
	var fcurWindowHeight = firstObj.height();
	var scurWindowHeight = secObj.height();
	$("#slider1000").animate({
		height: fcurWindowHeight
		}, 1000, function() {
	});
	$("#slider2000").animate({
		height: scurWindowHeight
		}, 1000, function() {
	});
			
	$("#sliderpress").easySlider({
	  pause: 4000,
		auto: false,
		continuous: true,
		prevText: '',
		nextText: '',
		nextId: "sliderpressnext",
		prevId: "sliderpressprev"
	});
	
	$("a.eventlink").fancybox({
		'overlayColor'    : '#FFF',
		'overlayOpacity'  : '.7',
		'opacity'		      : true,
		'overlayShow'	    : true,
  	'autoScale'			  : false,
  	'autoDimensions'  : false,
  	'width'           : 350,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'centerOnScroll'  : false,
		'titleShow'       : false
	});
	
	
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("news-active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("news-active"); //Remove any "active" class
		$(this).addClass("news-active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	//product page dropdown
	$("#product-select").change(onSelectChange);
	
	//$("div.maps").hide();
	//$("div.maps:first").addClass("map-active").show();
 /*
	$("a.maplink").click(function() {
    $("div.map-active").hide();
    var activeMap = $(this).attr("href");
    $(activeMap).addClass("map-active").show("slow");

	if ($(this).attr("href") == "#america" || $(this).attr("href") == "#asia" || $(this).attr("href") == "#europe"){
		$('#america #contact').css({'background-color' : '#485F63'});
		$('#europe #contact').css({'background-color' : '#485F63'});
		$('#asia #contact').css({'background-color' : '#485F63'});
		return false;
	}

	return false;
  });*/
	
	//init
	storeLocator();
	
	// GALLERY
	// HIDE CAPTION
	$('.gallery-caption').hide();
	// FADE IN CAPTION
	/*$('.gallery-image').mouseover(function(){
	  $(this).next('div.gallery-caption').show();
	  return false;
	});

	// FadeOut
	$('.gallery-image').mouseout(function(){
	  $(this).next('div.gallery-caption').hide();
	  return false;
	});
	*/
	$("#gallery-slider").easySlider({
    pause: 6000,
		auto: false,
		continuous: false,
		prevText: '',
		nextText: '',
		nextId: "slidergallerynext",
		prevId: "slidergalleryprev"
	});
  
});
	
function onSelectChange(){
	var selval = $("#product-select option:selected").val();
	$.scrollTo('#'+selval, 800, { axis:'y' });
}

function storeLocator(){
	$('#cities-select').hide();
	$(".usa, .eu, .am, .as, .deu, .spa, .aust, .fra, .gre, .unk, .bel, .ita, .denm, .csz, .tur, .slo, .net, .cana, .thai, .japan, .ukr, .grec").hide();
	var zmOutchar = "wm";
	$(".wm .dna").bind('click', function() {
		$(".wm").fadeOut("fast");
	 	$(".am").fadeIn("fast");
		$("a.lupe").show();
		zmOutchar = "am";
	});
	$(".am .dca").click(function() {
		$(".am").fadeOut("fast");
		$(".cana").fadeIn("fast");
		$("a.lupe").show();
		zmOutchar = "can";
	});
	$(".am .dus").click(function() {
		$(".am").fadeOut("fast");
		$(".usa").fadeIn("fast");
		$("a.lupe").show();
		zmOutchar = "usa";
	});
	$(".as .dth").click(function() {
		$(".as").fadeOut("fast");
		$(".thai").fadeIn("fast");
		$("a.lupe").show();
		zmOutchar = "thai";
	});
	$(".as .dja").click(function() {
		$(".as").fadeOut("fast");
		$(".japan").fadeIn("fast");
		$("a.lupe").show();
		zmOutchar = "jap";
	});
	$(".usa a, .eu a, .as a, .deu a, .fra a, .unk a, .spa a, .tur a, .gre a,.ita a, .csz a, .slo a, .net a, .wm .wmdeu, .wm .dna, .wm .das, .bel a, .denm a, .cana a, .thai a, .japan a, .aust a, .ita a, .dist-map .usa, .dist-map .am, .dist-map .ca, .dist-map .eu, .dist-map .as, .dist-map a, .grec a").mouseover(function() {
		$(this).addClass("active");
	});
	$(".usa a, .eu a, .as a, .deu a, .fra a, .unk a, .spa a, .tur a, .gre a, .ita a, .csz a, .slo a, .net a, .wm .wmdeu, .wm .dna, .wm .das, .bel a, .denm a, .cana a, .thai a, .japan a, .aust a, .ita a, .dist-map .usa, .dist-map .am, .dist-map .ca, .dist-map .eu, .dist-map .as, .dist-map a, .grec a").mouseout(function() {
		$(this).removeClass("active");
	});
	$(".wm .wmdeu").click(function() {
		$(".wm").fadeOut("fast");
		$(".eu").fadeIn("fast");
		$("a.lupe").show();
		zmOutchar = "eu";
	});
	$(".wm .das").click(function() {
		$(".wm").fadeOut("fast");
		$(".as").fadeIn("fast");
		$("a.lupe").show();
		zmOutchar = "as";
	});
	$(".eu .dge").click(function() {
		overallEu();
		$("li.deu").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dau").click(function() {
		overallEu();
		$("li.aust").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dsp").click(function() {
		overallEu();
		$("li.spa").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dfr").click(function() {
		overallEu();
		$("li.fra").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .grc").click(function() {
		overallEu();
		$("li.gre").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .uk").click(function() {
		overallEu();
		$("li.unk").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dbe").click(function() {
		overallEu();
		$("li.bel").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dit").click(function() {
		overallEu();
		$("li.ita").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dde").click(function() {
		overallEu();
		$("li.denm").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dtr").click(function() {
		overallEu();
		$("li.tur").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dcz").click(function() {
		overallEu();
		$("li.csz").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dsl").click(function() {
		overallEu();
		$("li.slo").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dukr").click(function() {
		overallEu();
		$("li.ukr").fadeIn("fast");
		zmOutchar = "euland";
	});
	$(".eu .dnet").click(function() {
		overallEu();
		$("li.net").fadeIn("fast");
		zmOutchar = "euland";
	});
	//overall europe function
	
	$("a.lupe").click(function(){
		$("ul.st-map li").hide();
		$('#dropdownmenu').html("");
		$("#stores-container").fadeOut("fast");
		$('#stores-slider').html("");
		$("h1.cityHeading").html("");
		
		if (zmOutchar == "eu" || zmOutchar =="am" || zmOutchar == "as"){
			$(".wm").fadeIn("fast");
			var char = "wm";
			$("a.lupe").hide();
		}
		else if (zmOutchar == "euland"){
			$(".eu").fadeIn("fast");
			zmOutchar = "eu";
		}
		else if (zmOutchar == "usa" || zmOutchar == "can"){
			$(".am").fadeIn("fast");
			zmOutchar = "am";
		}
		else if (zmOutchar == "thai"){
			$(".as").fadeIn("fast");
			zmOutchar = "as";
		}
		else if (zmOutchar == "jap"){
			$(".as").fadeIn("fast");
			zmOutchar = "as";
		}
	})
	
	//deutschland region click
	$("#stores-container").hide();
	$("h1.cityHeading").html("");
	$(".deu a, .usa a, .cana a, .fra a, .gre a, .unk a, .denm a, .spa a, .bel a, .ita a, .tur a, .ukr a, .csz a, .slo a, .net a, .thai a, .japan a, .aust a, .grec a").click(function(){
		var stateValue = $(this).html();
		loadState(stateValue);
		clearMaponState();
	});
	
	//Special with no extra map
	$(".eu .dlux").click(function(){
		var stateValue = "Luxembourg"; 
		loadState(stateValue);
	});
	$(".as .dko").click(function(){
		var stateValue = "Seoul"; 
		loadState(stateValue);
	});
	$(".as .dph").click(function(){
		var stateValue = "Philippines"; 
		loadState(stateValue);
	});
	$(".as .dmac").click(function(){
		var stateValue = "Macau"; 
		loadState(stateValue);
	});
	$(".as .dhk").click(function(){
		var stateValue = "Hong Kong"; 
		loadState(stateValue);
	});
}
//clear map on state click
function clearMaponState () {
	$("#stores-container").fadeOut("fast");
    $('#stores-slider').html("");
	$("h1.cityHeading").html("");
}
//overall europe function
function overallEu(){
	$(".eu").fadeOut("fast");
	$("a.lupe").show();
	$("h1.cityHeading").html("");
	$('#dropdownmenu').html("");
		$("#stores-container").fadeOut("fast");
      	$('#stores-slider').html("");
}

function loadState(city) {
	$.ajax({ 
		url: "index.php?id=105&type=5000",
		type: "POST",
	    cache: false,
	    data: {
	      city:city
	    },
		success: function(data){
		  //alert(data);
      	  $('#dropdownmenu').html(data);
		  //var firstStoreValue = $("#cities-select option:selected").val();
		  //var firstCityNameValue = $("#cities-select option:selected").val();
		  //loadStore(firstStoreValue, firstCityNameValue);
		  //onchange function
		  $("#cities-select").change(function () {
				if ($(this).val()== '0') {
					$("#stores-container").fadeOut("fast");
      				$('#stores-slider').html("");
					$("h1.cityHeading").html("");
				}
				else {
					var storesValue = $("#cities-select option:selected").val();
					var cityNameValue = $("#cities-select option:selected").val();
					loadStore(storesValue, cityNameValue);
				}
			});
    }
  });
}

function loadStore(stores, cityNameValue) {
	$.ajax({ 
		url: "index.php?id=106&type=5001",
		type: "POST",
	    cache: false,
	    data: {
	      stores:stores
	    },
		success: function(data){
		  //alert(data);
			$("#stores-container").fadeIn("fast");
			$('#stores-slider').html(data);
			$("h1.cityHeading").html(cityNameValue);
			$("#storesnext").remove();
			$("#storesprev").remove();
			$("#stores-slider").easySlider({
			   pause: 4000,
			  auto: false,
			  continuous: false,
			  prevText: '',
			  nextText: '',
			  nextId: "storesnext",
			  prevId: "storesprev"
			});
			var sliderzahl = $("#stores-slider div ul li").length;
			if (sliderzahl <= 2 ) {
				$("#storesnext").hide();
			}
    }
  });
}
