// funkce pro vlozeni fotek z fotogalerie ke clanku START
function GenerateCustomFckGallery(files_array)
{
		var result="";
		for (var a=0;a<files_array.length;a++)
			result+="<a class=\"nyroModal\" href=\""+files_array[a].path+"\" rel=\"gallery[myset]\"><img class=\"body-gallery\" alt=\"\" src=\""+files_array[a].thumb+"\" /></a>";
		return result;
}
// funkce pro vlozeni fotek z fotogalerie ke clanku END

try {
  $(function() {
  	$.fn.nyroModal.settings.processHandler = function(settings) {
  		var from = settings.from;
  		if (!settings.type && from && from.href) {
  			/*alert(
  				'type should be image: '+settings.type + '\n'
  				+ "need to determine if image manually");*/
  			var arr = from.href.split('?');
  			//if carrying extra stuff
  			if(arr.length>1){
  				var newArr=arr[0].split('.');
  				var newType=settings.type;
  				//alert('extension is: ' + newArr[newArr.length-1]);
  				switch(newArr[newArr.length-1].toUpperCase()){
  					case 'IMG':
  					case 'JPG':
  					case 'JPEG':
  					case 'PNG':
  					case 'GIF':
  					case 'ASPX':
  						newType='image';
  						break;
  					default:
  						newType=settings.type;
  				}
  				//alert("new type is " + newType);
  				$.nyroModalSettings({
  					type: newType
  				});
  			}
  		}
  	};
  	
  });



  $(document).ready(function(){       
    
    $("a.toolTip").ndTooltips();
    
    // Nastaveni Javascriptove validace prislusnym formularum dle ID
    $("#design, #contactForm, #workForm, #demoDriveForm, #orderProspect, #servisForm, #onlineServisesForm").ndFormValidator();
    
    
    // Zmena barvy pozadi po najeti mysi v sekci prislusentstvi
    $(".AccessoriesItem").hover(
      function(){$(this).css("background","#F2F2F2");},
      function(){$(this).css("background","none");}    
    );  
    
    // aktivovani leveho hover menu
  	$("#leftMenu").ndMenu({ type: "left" });
    
    
    // skryvani/odkrivani novinek
    $(".nItem h2 a").click(
      function(){    
       $(".nItem .perex").slideUp();
       var parent = $(this).parents(".nItem");     
       parent.find(".perex").slideDown("slow");      
       }
    );
    
    // skryvani/odkrivani poznámkových boxů u formuláře objednat servis
    $("#cs10, #ds12").click(
      function(){    
        var el =  $(this).parents("tr").next();
        if(el.css("display")=="none") {
          el.show();
          el.find("textarea").val('Poznámka...');
        } else {
          el.hide();
          el.find("textarea").val('');
        }
      }
    );
    
    // skryvani/odkrivani absolutne pozicovaneho obsahoveho boxiku v detailu vozu
    $("#absoluteContent .boxHead img").click(function () {
      if ($("#absoluteContent #boxBody").css("display")=="block") {
        $("#absoluteContent #boxBody").slideUp("slow");
        $(this).attr("src","/img/Bg_absoluteBoxArrowDown.gif");
      } else {
        $("#absoluteContent #boxBody").slideDown("slow");
        $(this).attr("src","/img/Bg_absoluteBoxArrow.gif");
      }
    });
    
    $("#chaptersMenu a").click(function () {
      var selItem = $(this).attr("class");
      var scrollItem = "."+selItem+"s";      
      var el = "#absoluteContent ."+selItem;      
      $("#absoluteContent .boxHead img").attr("src","/img/Bg_absoluteBoxArrow.gif");   
      $("#absoluteContent #boxBody").slideUp(150,function(){        
        $(el).css({"display":"none"});        
        $("#absoluteContent #boxBody .item").each(function(i) {          
          $(this).hide();    
          if($(this).hasClass(selItem)) {            
            $(scrollItem).addClass("show");
            $(scrollItem).removeClass("hidde");
            $(this).show();
            $("#absoluteContent #boxBody").slideDown();
          } else {            
            $(".chItem_"+(i+1)+"s").addClass("hidde");
            $(".chItem_"+(i+1)+"s").removeClass("show");
          }
        });
        
      });
    });
    
    $("#thumbs .item img").click(function () {
      if ($("#absoluteContent #boxBody").css("display")=="block") {
        $("#absoluteContent #boxBody").slideUp("slow");
        $("#absoluteContent .boxHead img").attr("src","/img/Bg_absoluteBoxArrowDown.gif");
      } else {
    
      }
    });
    
    
    
    // Ovládání mapy
    $(".city").hover(
      function () {
        var logoBox = $(this).find(".logoBox");
        var inBox = $(this).find(".inBox");
        var logoBoxWidth = 0;
        logoBox.find(".inBox a").each(function(){
          var thisWidth = parseInt($(this).css("width"));
          logoBoxWidth = logoBoxWidth+thisWidth+15;
        });
        inBox.css({"width":logoBoxWidth+"px"});
        logoBox
          .css({"width":logoBoxWidth+16+"px","visibility":"visible","zIndex":100,"marginLeft":((logoBoxWidth/2)*(-1))+"px"})
          .css({opacity: 0})
          .animate({opacity: 1} ,750);   
      }, 
      function () {
        $(this).find(".logoBox").css({"visibility":"hidden"});
      }
    );
  
    
    
    // kontrola formularovych prvku (disable/enable) - je potreba aby kontrolovane prvky mely class=control
    function controlForm(idForm) {
      var fId = idForm;
      var firstEl =  $(fId).find(".control:first");
      var lastEl =  $(fId).find(".control:last");
      var styles = {
        "background":"#F5F4EA",
        "border":"1px solid #C9C7BA"
      }
          
      $(fId).find(".control").attr("disabled", "disabled").css(styles);
      $(firstEl).removeAttr("disabled").removeAttr("style");
      
      $(fId).find("select").change(function(i){
        var myIndex = $(fId).find(".control").index(this);
        $(fId).find(".control").eq(myIndex+1).removeAttr("disabled").removeAttr("style")
        if($(this).val()=='') {
          $(fId).find(".control").eq(myIndex+1).attr("disabled", "disabled").css(styles);
        }
      });
      
      $(fId).find("input:text").keyup(function(i){
        var myIndex = $(fId).find(".control").index(this);
        $(fId).find(".control").eq(myIndex+1).removeAttr("disabled").removeAttr("style");
        if($(this).val()=='') {
          $(fId).find(".control").eq(myIndex+1).attr("disabled", "disabled").css(styles);
        }
      });    
    }  
    controlForm($("#demoDriveForm, #servisForm, #orderProspect"));
    
    // specialni funkce pro ovladani formulare objednat si demo jizdu
    var formularId = "#demoDriveForm";    
    if($(formularId).find("#markType").val()!='') {
      $(formularId).find("#model").removeAttr("disabled").removeAttr("style");
    } else {
      $(formularId).find("#model").attr("disabled", "disabled");
      //$(formularId).find("#model").find("option:first").attr("selected","selected");
    }  
    if($(formularId).find("#model").val()!='') {
      $(formularId).find("#dateVisit").removeAttr("disabled").removeAttr("style");
    }  
    $(formularId).find("#markType").change(function(){
      znacka = $(this).val();
      optionGroup = "optgroup[label="+ znacka +"]";    
      if($(formularId).find("#markType").val()!='') {
        $(formularId).find("#model").removeAttr("disabled");
      } else {
        $(formularId).find("#model").attr("disabled", "disabled");
        //$(formularId).find("#model").find("option:first").attr("selected","selected");
      }
      $(formularId).find("#model").find("optgroup").attr("disabled", "disabled");
      $(formularId).find("#model").find(optionGroup).removeAttr("disabled");
      
      $(formularId).find("#workroom").find("optgroup").attr("disabled", "disabled");
      $(formularId).find("#workroom").find(optionGroup).removeAttr("disabled");
      
      //$(formularId).find("#model").find(optionGroup).find("option:first").attr("selected","selected");
      
      if($(formularId).find("#model").val()!='') {
        $(formularId).find("#dateDay").removeAttr("disabled").removeAttr("style");
      }
      
    });
    
    // specialni funkce pro ovladani formulare objednat si servis
    var formularId2 = "#servisForm";  
    if($(formularId2).find("#model").val()!='') {
      $(formularId2).find("#dateDay").removeAttr("disabled").removeAttr("style");
    }
    
    if($(formularId2).find("#markType").val()!='') {
      $(formularId2).find("#model").removeAttr("disabled").removeAttr("style");
    } else {
      $(formularId2).find("#model").attr("disabled", "disabled");
      //$(formularId2).find("#model").find("option:first").attr("selected","selected");
    }  
    if($(formularId2).find("#model").val()!='') {
      $(formularId2).find("#dateDay").removeAttr("disabled").removeAttr("style");
    }
    
    $(formularId2).find("#markType").change(function(){
      znacka = $(this).val();
      optionGroup = "optgroup[label="+ znacka +"]";    
      $(formularId2).find("#workroom").find("optgroup").attr("disabled", "disabled");
      $(formularId2).find("#workroom").find(optionGroup).removeAttr("disabled");
      if($(formularId2).find("#model").val()!='') {
        $(formularId2).find("#dateDay").removeAttr("disabled").removeAttr("style");
      }     
    });
    
    $(formularId2).find("#rCar").click(function () {
      $(formularId2).find("#rCarBox").toggle();
      if($(formularId2).find("#rCarBox:visible")) { 
        $(formularId2).find("#rCarL").attr("checked","checked");
      } else {
        $(formularId2).find("#rCarL").removeAttr("checked");
      }
    });
    
    // specialni funkce pro ovladani formulare objednat si prospekt
    var formularId3 = "#orderProspect";  
    if($(formularId3).find("#model").val()!='') {
      $(formularId3).find("#dateDay").removeAttr("disabled").removeAttr("style");
    } 
    
    $(formularId3).find("#markType").change(function(){
      znacka = $(this).val();
      optionGroup = "optgroup[label="+ znacka +"]";    
      if($(formularId3).find("#markType").val()!='') {
        $(formularId3).find("#model").removeAttr("disabled");
      } else {
        $(formularId3).find("#model").attr("disabled", "disabled");
        //$(formularId3).find("#model").find("option:first").attr("selected","selected");
      }
      $(formularId3).find("#model").find("optgroup").attr("disabled", "disabled");
      $(formularId3).find("#model").find(optionGroup).removeAttr("disabled");
      
      $(formularId3).find("#workroom").find("optgroup").attr("disabled", "disabled");
      $(formularId3).find("#workroom").find(optionGroup).removeAttr("disabled");
      
      //$(formularId3).find("#model").find(optionGroup).find("option:first").attr("selected","selected");
      
      if($(formularId3).find("#model").val()!='') {
        $(formularId3).find("#dateDay").removeAttr("disabled").removeAttr("style");
      }
      
    });
  
    $(".allForms").find(".date-pick").change(function () {
     if($(".date-pick").val()!='') {
        $(".allForms").find("#hour").removeAttr("disabled");
        $(".allForms").find("#hour").removeAttr("style");
      }
    });
       
  });


// funkce pro zrušení defaultního textu input pole END

function KillDefaultText(elementValue,elementId) {
  if(document.getElementById(elementId).value == elementValue) {
    document.getElementById(elementId).value = "";
  }
}

// funkce pro zrušení defaultního textu input pole END

// funkce pro zpětné vložení def. textu START

function PasteDefaultText(elementValue,elementId) {
  if(document.getElementById(elementId).value == "") {
    document.getElementById(elementId).value = elementValue;
  }  
}

// funkce pro zpětné vložení def. textu END

  function callMessageBox(message) {
    $(document).ready(function(){  
      $.nyroModalManual({      
        minWidth: 300,
        minHeight: 80,      
        bgColor: '#E0E0E0',      
        content: message,
        css: {      
          wrapper: {
            background: '#ffffff url(../img/info.gif) no-repeat 10px 10px',
            padding: '10px 10px 10px 60px',
            border:'3px solid #007AC3'
          },
          content: {          
            padding: '10px'         
          }        
        }
      });
      
    });
  }



	
			
$(document).ready(function(){
		                                       		
		// ------------------------------------
		// hlavni KONFIGURACE pluginu
		// ------------------------------------
		
		var thumbs				= "#thumbs";
		var thumbsControl		= thumbs + " a";
		
		var navigation			= "span#navigation";
		var navigationControl	= navigation + " a";
		
		var largePhotoCanvas	= "#largePhoto";		
		var largePhotoImage		= largePhotoCanvas + " img";
		
		var image = $('<img />').attr('src', 'img/auta/auto1.jpg');

				
		// ------------------------------------
		// ukazani pozadovane fotografie
		
		function showActive(index){
			$(thumbsControl).removeClass("active");
			$(thumbsControl).eq(index).addClass("active");
			
			var activeHref = $(thumbsControl).eq(index).attr("href");															
						
			$(largePhotoImage).hide();
						
			$(largePhotoImage).attr("src", activeHref);
			$(largePhotoControl).attr("href", activeHref);						
			$(largePhotoImage).show(); 						 
		}
		
		// ------------------------------------
		// kliknuti na nahledovou fotografii
		
		$(thumbsControl).click( function(){			
			$('#largePhoto img').remove();		
			$(thumbsControl).removeClass("active");
			$(this).addClass("active");
			
			var activeHref = $(this).attr("href");															
						
			image.fadeOut(200);
			image.attr("src", activeHref);			
															
			image.load(function(){ 
				$('#largePhoto').append( $(this) ); 				
				$(this).hide();
				$(this).fadeIn(200);
			
			});
						
			return false;
			
		});
		
		//$('#largePhoto').append(image);				
		
		//$("#thumbs .item img").crop({ x: 400, y: 0, height: 127, width: 38, transparentURL: 'http://remysharp.com/wp-content/uploads/2007/03/transparent.gif' })																
																										
	});



//Grayscale Function - odstiny sedi START

function AddEventHandler(object,event,handler)
{
	if ((object==null)||(event==null)||(handler==null))
		return;
		
	if (object.attachEvent)
		object.attachEvent("on"+event,handler);
	else
		object.addEventListener(event,handler,false);
}

$(document).ready(function() {	
  
  $('#otherMenu li').hover(function() {
    grayscale.reset( $(this).find('img') );                
	}, function() {
	  if(!$(this).hasClass('active')) {
		  grayscale( $(this).find('img') );
		}
  });
  
  $('#thumbs img').hover(function() {
    grayscale.reset( $(this) );                
	}, function() {	  
		  grayscale( $(this) );		
  });
  
  function controlGray() {
    $('#otherMenu li').each(function(i) {
      //alert($(this).hasClass('active'));
      if($(this).hasClass('active')) {
        grayscale.reset($(this).find('img'));
      } else {
        grayscale($(this).find('img'));
      }
    });
  }
  
  function controlGray2() {
    $('#thumbs img').each(function(i) {
      //alert($(this).hasClass('active'));       
        grayscale($(this));
      
    });
  }
  AddEventHandler(window,"load",function() {controlGray2()});
  AddEventHandler(window,"load",function() {controlGray()});
  
});

//Grayscale Function - odstiny sedi END



Date.format = 'dd.mm.yyyy';
$(function()
{
	$('.date-pick').datePicker(
    {
      clickInput:true,
      renderCallback:function($td, thisDate, month, year)
				{
					if (thisDate.getDay()==0) {						
						$td.addClass('disabled');
					}
				}
      //startDate:'01/01/1996'
    });
});

} catch(err) {

}

