/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id=\"preview\"><img src='"+ this.rel +"' alt=\"Image preview\" />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.css("z-index", 10000);
	});			
};

$(document).ready(function($)
{
	imagePreview();
});


/**** Telephone Format Remove ****/
$(document).ready(function()
{
	$.geekSkypeRemover(10000);
});


/**** FORM VALIDATION METHODS by Arlind Nushi ****/

function checkField(field, no_focus)
{
	if( field.val().length == 0 )
	{
		field.css("border", "1px solid red");
		
		if( !no_focus )
			field.focus();
		
		field.blur(function()
		{
			checkField(field, 1);
		});
		
		return false;
	}
	else
	{
		field.css("border", "1px solid #D6D9DB");
		return true;
	}
}

function checkEmailField(field, no_focus)
{
	if( field.val().length == 0 || !field.val().match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,5})+$/) )
	{
		field.css("border", "1px solid red");
		
		if( !no_focus )
			field.focus();
		
		field.blur(function()
		{
			checkField(field, 1);
		});
		
		return false;
	}
	else
	{
		field.css("border", "1px solid #D6D9DB");
		return true;
	}
}




/*
 * jquery.geekSkypeRemover.js - jQuery plugin to remove Skype Call buttons
 * 
 * Version 1.0
 * 
 * This plugin extends jQuery with a new function:
 * 
 *   - $.geekSkypeRemover(10000)
 *       Check for Skype Call buttons for a maximum of 20 seconds.
 * 
 * This function checks for 'Skype Call' buttons dynamically created by the
 * Skype Browser Plugin for a defined period of time and replaces any such
 * buttons it finds with the original textual telephone number content.
 * 
 * The predefined period of time is required since the Skype Browser Plugin
 * might take a few seconds to add the Skype Call buttons after loading of
 * the page completes.
 * 
 * Simply replacing the elements dynamically added by the Skype Browser Plugin
 * with the original textual telephone numbers would cause Skype to recreate
 * the Skype buttons, so this plugin inserts the original textual telephone
 * numbers with hidden underscores ("_") as the second characters.
 * 
 * The following metatag is supposed to perform the same function, but it works
 * inconsistently across browsers and DOCTYPES:
 * 
 *   <meta name="SKYPE_TOOLBAR" CONTENT="SKYPE_TOOLBAR_PARSER_COMPATIBLE">
 *
 *   <!-- sphoneid telnr="+27210000000" fileas="Willem van Zyl" -->021 000 0000<!-- sphoneid -->
 * 
 * 
 * This code is in the public domain.
 * 
 * Willem van Zyl
 * willem@geekology.co.za
 * http://www.geekology.co.za/blog/
 */
(function($) {
 
  /**
   * Remove Skype Call buttons that were dynamically added, e.g.:
   * 
   *   $(document).ready(function() {
   *     $.geekSkypeRemover(10000);
   *   }
   */
  $.geekSkypeRemover = function(microsecondsLeft) {
 
    //check if the predefined time limit was reached:
    if (microsecondsLeft == 0) {
      return false;
    }
 
    microsecondsLeft = microsecondsLeft - 500;
 
 
    //seek elements added by the Skype Browser Plugin; remove them if
    //they exist or try again in microsecondsLeft microseconds if they don't:
    if ($('span.skype_pnh_container').length == 0) {
      //no Skype Call buttons exist (yet):
      setTimeout('$.geekSkypeRemover(' + microsecondsLeft + ')', 500);
    } else {
      //Skype Call buttons exist:
      var originalText = '';
 
      //determine and set the original textual telephone number:
      $('span.skype_pnh_print_container').each(function() {
        originalText = $(this).html();
        originalText = originalText.substring(0,1) + '<span style="display: none;">_</span>' + originalText.substring(1);
        $(this).after(originalText);
      });
 
      //remove the Skype Call button elements:
      $('span.skype_pnh_container').remove();
      $('span.skype_pnh_print_container').remove();
    }
 
 
    return true;
 
  };
 
})(jQuery);




(function() {
  /*
    EnablePlaceholder jQuery plugin.
    https://github.com/marioizquierdo/enablePlaceholder
    version 1.2.2 (Oct 02, 2011)
    
    Copyright (c) 2011 Mario Izquierdo
    Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
    and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  */
  "use strict";
  var $, execute_plugin_method, on_focusin_clear_placeholder, on_focusout_show_placeholder;
  $ = jQuery;
  $.support.placeholder = document.createElement('input').placeholder != null;
  $.EnablePlaceholder = {
    "defaults": {
      "withPlaceholderClass": "placeholder"
    },
    "alsoForModernBrowsers": false
  };
  execute_plugin_method = function($elements, options, lambda) {
    var settings;
    if (!$.support.placeholder || $.EnablePlaceholder.alsoForModernBrowsers) {
      settings = $.extend({}, $.EnablePlaceholder.defaults, options);
      return $elements.each(function() {
        return lambda($(this), settings);
      });
    }
  };
  on_focusin_clear_placeholder = function(input, settings) {
    return input.bind('focus focusin keydown paste', function() {
      return input.clearPlaceholder(settings);
    });
  };
  on_focusout_show_placeholder = function(input, settings) {
    return input.bind('blur focusout', function() {
      return input.showPlaceholder(settings);
    });
  };
  $.fn.enablePlaceholder = function(options) {
    return execute_plugin_method(this, options, function(input, settings) {
      on_focusin_clear_placeholder(input, settings);
      on_focusout_show_placeholder(input, settings);
      input.parents('form').submit(function() {
        input.clearPlaceholder(settings);
        return true;
      });
      $(window).unload(function() {
        input.clearPlaceholder(settings);
        return true;
      });
      return input.showPlaceholder(settings);
    });
  };
  $.fn.showPlaceholder = function(options) {
    return execute_plugin_method(this, options, function(input, settings) {
      if (input.val() === "") {
        return input.val(input.attr("placeholder")).addClass(settings.withPlaceholderClass).data('ph_active', true);
      }
    });
  };
  $.fn.clearPlaceholder = function(options) {
    return execute_plugin_method(this, options, function(input, settings) {
      if (input.data('ph_active')) {
        return input.val("").removeClass(settings.withPlaceholderClass).data('ph_active', false);
      }
    });
  };
  $.fn.updatePlaceholder = function(new_placeholder_text, options) {
    return this.clearPlaceholder(options).attr('placeholder', new_placeholder_text).showPlaceholder(options);
  };
}).call(this);


$(document).ready(function()
{
	$('input[placeholder], textarea[placeholder]').enablePlaceholder();
	
	$(".site_by_trokit").siteByTrokit({color: 'white', direction: 'left'});
});



jQuery.fn.siteByTrokit = function(options){
    var $this = $(this);
    $this.attr("title", "Site by Trokit.com");
    
    var images = {
        white: 'http://trokit.com/brand/site_by_trokit_white.png',
        black: 'http://trokit.com/brand/site_by_trokit_black.png'
    };
    
    var load_img = images.black;
    var direction = "right";
    
    if( options && options.color )
    {
        switch( options.color )
        {
            case "white":
                load_img = images.white;
                break;
                    
            case "black":
                load_img = images.black;
                break;
        }
    }
    
    var real_width = 58;
    var collapsed_width = 16;
    var delay = 200;
    var opacity = 0.4;
    
    $this.css({
        position: 'relative',
        display: 'inline-block',
        textIndent: "-99999px",
        width: collapsed_width,
        height: 16,
        background: "url(" + load_img + ") no-repeat left center"
    }).fadeTo(0, opacity);
    
    $this.hover(
    function(){        
        $this.stop();
        $this.fadeTo(delay, 1);
        $this.animate({width: real_width});
    }, 
    function(){
        $this.stop();
        $this.animate({width: collapsed_width}, function(){
            $this.fadeTo(delay, opacity);
        });
    });
};
