/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($) {

$.fn.hint = function (blurClass) {
  if (!blurClass) {
    blurClass = 'blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = $(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = $(this.form),
      $win = $(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) {
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

})(jQuery);

jQuery.noConflict();

jQuery(function($) {
	
    // folding
	jQuery('.foldedTrigger').addClass("closed");
	jQuery('.closed').live("click", function () {
		$(this).nextAll('.foldedShow').hide();
	  if(jQuery('#opened')[0]){
	    jQuery(this).parent().children('.foldedHide').slideUp("slow");
	  } else {
      	    jQuery(this).parent().children('.foldedHide').slideDown("slow");
	  }
	  jQuery(this).removeClass("closed").addClass("opened");
	});
	
	jQuery('.opened').live("click", function () {
		$(this).nextAll('.foldedShow').show();
	  if(jQuery('#opened')[0]){
	    jQuery(this).parent().children('.foldedHide').slideDown("slow");
	  } else {
      	    jQuery(this).parent().children('.foldedHide').slideUp("slow");
	  }
	  jQuery(this).removeClass("opened").addClass("closed");
	});
	
	// menu last item
	$('#mainMenu ul li:last-child').addClass("lastItem");
	$('#mainMenu ul li ul>li:first-child').addClass("firstItem");
	
	// main menu ie6 functionality
	if(jQuery.browser.msie){
 		if(jQuery.browser.version <= 7){ 			
			jQuery('#mainMenu ul>li').mouseenter(function(){
				jQuery(this).addClass('hover');
				jQuery(this).children('ul').css({"left":"0"});
			});
			jQuery('#mainMenu ul>li').mouseleave(function(){
				jQuery(this).removeClass('hover');
				jQuery(this).children('ul').css({"left":"-9999px"});
			});
			$('#breadcrumbs > li:first-child').addClass('first-child')
 		}
 	}
	
	//Language switcher
	var $lang = $('#lang');
	$lang.click(function(event){
		var $el = $(event.target);
		if ($el.is('.active')) {
			$lang.addClass('show');
			$el.removeClass('active');
			
			//Setting a close event
			$(document).click(function(event){
				var $docTarget = $(event.target).closest('#lang');
				if (!$docTarget.is('#lang')) {
					$lang.removeClass('show');
					$el.addClass('active');
					document.unbind('click');
				}
			});
			
			event.preventDefault();
			return false;
		}
	});

        //lightbox
        if (jQuery('.image a')[0]) {
                jQuery('.image a').lightBox();
        }

        //cycle
        jQuery('#subHeader .anchor-stdWrap-link').remove();

        if (jQuery('.headerItem')[0]) {
                jQuery('#subHeader').cycle({ fx:'scrollLeft', timeout: 6000  });
        }
        
        //contact input hints
        $('#contact .tx_powermail_pi1_fieldwrap_html').each(function(){
        	var myTitle = $(this).children('label').children('a').children('dfn').text();
        	console.log(myTitle);
        	$(this).children('input').attr('title', myTitle);
        	$(this).children('textarea').attr('title', myTitle);
        	
        });
        
        // input hint
	if($('#contact input, #contact textarea')[0]){
		$('#contact input, #contact textarea').hint();
	}
	
	$('#powermaildiv_uid21,#powermaildiv_uid27').after('<div style="clear:both;"></div>');

	/*if( $('#subHeader .headerItem')[1]) {
			 $('#subHeader').css('margin-bottom','30px');
	}*/
});

function SendForm() {
	var newUrl = '';
	var valCal = '';
	
	for (i=1;i<8;i++) {
		valCat = document.getElementById('cat'+i).options[document.getElementById('cat'+i).selectedIndex].value;
		if (valCat!=0) {
			if (newUrl=='') newUrl = valCat;
			else newUrl = newUrl + "," + valCat;
		}
	}
	document.getElementById('allCatgeories').value = newUrl;
	document.getElementById('selectorForm').submit();
}
