/**
 * JQuery sets
 *
 * @date 21.05.2010 13:04:40
 *
 */



  /**
   * Produkty, kategorie
  */
  $(document).ready(function(){

        $("#category input.submit").hide();

        $("#category").change(manage);
        
        function manage(){

          var val = $("#category input[@name='cat']:checked").val();
          //$(this).attr('checked', 'checked');

          $(".products>div.c"+val+"").show(); //.c1, .c2
          $(".products>div:not(.c"+val+")").hide();

        }
        
        
        
      $('.products a').click(function(){
          var href = $(this).attr('href');
          window.open(href);
          return false;
      });

        

  });
  
  
  



  /**
   * Tooltip
   * http://craigsworks.com/projects/qtip/docs/tutorials
  */
    $(document).ready(function() {

      $('#car a[title]').qtip({
         show: 'mouseover',
         hide: 'mouseout',
         style: {border: {width: 2,  radius: 0, color: '#eeeeee'}, name: 'light', tip:true}
         //style: {border: {width: 2,  radius: 0, color: '#eeeeee'}, name: 'light', tip:'bottomLeft'},
         //position: {corner: {target:'topRight',  tooltip: 'bottomLeft'}}

      });

    });
    

    
  /**
   * Cufón
  */
    $(document).ready(function() {

      Cufon.replace('h3, #nav a', { fontFamily: 'Dax Regular', hover:true });
      Cufon.replace('h2, #sidebar h3, #boxes h3, #content h3', { fontFamily: 'Dax Medium', hover:true });
      
      

    });





  /** 
   * Youtube Player z linku
  */
    $(document).ready(function(){
    
      var width = "509";
      var height = "414";
      
      $('a[href^="http://youtube.com"], a[href^="http://www.youtube.com"]').each(function(){
      
        var videoURL = $(this).attr("href");
        var embedPlayer =  '<object width="'+ width +'" height="'+ height +'"><param name="movie" value="'+ videoURL +'&hl=cs_CZ&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+ videoURL +'&hl=cs_CZ&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+ width +'" height="'+ height +'"></embed></object>';
        $(this).replaceWith(embedPlayer);

      });

    });




  /**
   * Google maps
  */
  $(document).ready(function() {
  
      $('#map_canvas').googleMaps({
          markers: {
              latitude: 	37.4416,
              longitude: -122.1516,
              info: {
                  layer: '#address'
              }
          }
      });
  });









  /**
   * SVG mapa
   * v ostre verzi - nastavit cesty - xml, click
  */
  $(window).bind('load', function(){

  	if($('#map').size() && Raphael){

  		$.get("http://localhost/Projects/Auftec/ftp/js/map-all.xml", function(svg){ //absolutni cestu udat!
  		//$.get("/js/map-all.xml", function(svg){ //absolutni cestu udat!
  		
        // nastaveni barev
        var bgColor = "#dddddd";
        var bgHoverColor = "#464646";
        var strokeColor = "#fff";

        // nastaveni mapy
  		  var attrOkres = {fill: bgColor, stroke: strokeColor, cursor: 'pointer', "stroke-width": 1, "stroke-linejoin": "round" };
  		  var attrKraj = {stroke: strokeColor,  cursor: 'pointer', "stroke-width": 0, "stroke-linejoin": "round"};
        var areaType = $('#areaType').val() || 'cr';
        var areaId = $('#areaId').val() ;
        var paperSize = { width: 410, height: 240 };
        var bbox = { x: 0, y: 0, width: paperSize.width, height: paperSize.height };
        var translate = { x: 0, y: 0 };
        var scale = 1;
        var R = Raphael("map", paperSize.width, paperSize.height);
        //$('.caption').html('<h3>Vyberte kraj</h3>');

        // zobrazovana plocha
        var renderArea = function($path, attr, transform){

    			transform = transform || false;
    		  var key = $path.attr('id');
    		  var d = $path.attr('d');
    			var label = $path.attr('inkscape:label');
    			if(areaType != 'cr') label = 'Okres ' + label;
    			var kraj = R.path(attr, d);
    				
          var keyAct = key + ".html";
          var urlKey = activeKeyFromURL(); // vraci key.html, nutno upravit orig klic pro porovnani

          // vyznaceni aktivniho kraje dle parametru z URL
          if(keyAct == urlKey){
            kraj.attr({ fill: bgHoverColor});
          }

          // udalosti na kraji
   				$(kraj.node)
    					.bind('mouseenter', function(e)	{
     					  if($.browser.mozilla || $.browser.msie || $.browser.webkit || $.browser.opera) kraj.animate({ fill: bgHoverColor}, 200);
    						else kraj.attr({ fill: bgHoverColor});
    						$('.caption').html('<p>' + label + '</p>');
    					})
    					.bind('mouseout', function(e)	{

                if(keyAct != urlKey){ // neaplikovat na prokliknuty kraj
       						if($.browser.mozilla || $.browser.msie) kraj.animate({ fill: bgColor }, 200);
      						else kraj.attr({ fill: bgColor});
      						$('.caption').empty();
                }
                
    					})
    					.bind('click', function(e){
    					   //return window.location.href = '#'+key;
    					  //return window.location.href = '/partneri/' + keyAct;
    					  return window.location.href = keyAct;
    					});
    			};


          // vykresleny cele mapy
    			if(areaType == 'cr'){

    				var $cr = $('g#layer1 path', svg);
    				var cr = R.path(attrKraj, $cr.attr('d'));
    				cr.scale(scale, scale);
    				cr.translate(translate.x, translate.y);

            // vykresleni jedn. okresu do plochy
    			  $('g#layer2 path', svg).each(function()	{
    					renderArea($(this), attrOkres, 1);
    				});

    			}

  		});
  	}
  });
  


  /**
   * Vraci ID prokliknuteho kraje, z URL (kraj-plzensky),
   * resit jinak pres regexp
  */
  function activeKeyFromURL(){
  
    var position;
    //var path = window.location.hash;
    var path = window.location.pathname;

    if ((position = path.indexOf('kraj-')) != -1 ) {
      var key = path.substr(position);
      //key = key.substr(key.indexOf('.html'));
    }
    
    return key; // obsahuje i priponu html!
    
  }

  




