/**
 * initialize global variables
 */

// width of rounded corner in main menu
var roundedCornerWidth = 7;												

// hide main navi on page load to prevent navi links from "jumping" during vertically centering
swfobject.createCSS("div#tia-navi", "visibility: hidden");

// hide content on page load
swfobject.createCSS("div#bg-img", "visibility: hidden");
swfobject.createCSS("div#tia-icons", "visibility: hidden");
swfobject.createCSS("div#tia-header", "visibility: hidden");
swfobject.createCSS("div#tia-stitches", "visibility: hidden");
swfobject.createCSS("div#tia-navi", "visibility: hidden");
swfobject.createCSS("div#tia-main", "visibility: hidden");

jQuery(function($){

   // path to flash player
	var pathPLAYERtmp = pathIMG.split('/'); 
	var pathPLAYER = '';
	for(i=0; i<pathPLAYERtmp.length-2; i++) {
		pathPLAYER += pathPLAYERtmp[i]+'/';
	}
	
	// set isAccordion variable if it's not set already (used to check for accordion functionality; defaults to true) 
	if( typeof(isAccordion) == "undefined" ) isAccordion = true;
	// set default accordion tab to 0 (first tab) if it's not already set  
	if( typeof(accordionDefaultId) == "undefined" ) accordionDefaultId = 0;
	
	/**
	 * show content when window is loaded
	 */
	$(window).load( function() {
		$('div#bg-img, div#tia-header, div#tia-stitches, div#tia-navi, div#tia-main, div#tia-icons').css({'visibility':'visible'});
	});	
	/*if ($.browser.msie) {
		$(window).scroll( function() {
			$('div#bg-img').css('top', document.documentElement.scrollTop);
		});
	}*/
	if ($('div.marginalContent').children().length > 0) {
		$('div#tia-sidebar').children(':not(.tia-contact)').remove();
		$($('div.marginalContent').children()).appendTo('div#tia-sidebar');
	}
	$(window).load( function() {
		$('div#tia-sidebar').css({'visibility':'visible'});
	});
	
	/**
	 * apply png fix for IE6
	 * uses plugin jquery_pngFix.js, http://jquery.khurshid.com/ifixpng.php
	 */
	if( $.browser.msie && parseInt($.browser.version) < 7 ) {
		$.ifixpng(pathIMG+'tia/img/blank.gif');
		$('div.fixpng').ifixpng();
		$('img[src$=.png]').ifixpng();
	}
	
	/**
	 * center background image
	 */
	repositionBG();
	$(window).resize( function() {
		repositionBG();
	});
	function repositionBG() {
		$('#bg-img').css({
			'width' : $('#bg-img').width()+($('#bg-img img').width()/2-$(window).width()/2)+'px',
			'left' : -($('#bg-img img').width()/2-$(window).width()/2)+'px'
		});
	}
	
	/**
	 * TIA main menu
	 * uses superfish plugin, http://users.tpg.com.au/j_birch/plugins/superfish/
	 */
	var mainMenuWidth = parseInt($("div#tia-navi").css('width'));		// width of main menu
	var mainMenuHeight = parseInt($("div#tia-navi").css('height'));		// height of main menu
	var menuCount = $("ul.sf-menu").children().length;					// amount of main menu items
	var menuItemMarginRight = parseInt($("ul.sf-menu").children().css('margin-right')); // right margin of menu items
	
	// set width of menu items according to amount of items
	var menuItemMinWidth = Math.ceil((mainMenuWidth-(menuCount*menuItemMarginRight)-roundedCornerWidth) / menuCount);
	$("ul.sf-menu").children().width( menuItemMinWidth );
	var menuDiff = $("ul.sf-menu").width()+2-($("ul.sf-menu").children().width()*menuCount+roundedCornerWidth+(menuCount)*menuItemMarginRight);
	$("ul.sf-menu > li.last").width( $("ul.sf-menu > li.last").width()+menuDiff );
	
	// initialize main menu
	$("ul.sf-menu")
		.supersubs({minWidth: menuItemMinWidth, maxWidth: 330, extraWidth:  0})
		.superfish({autoArrows:  false, dropShadows: false, delay: 300, disableHI: true, onHide:removeRoundedCorner}); 
	$(".sf-menu li.last > a")
		.css({'background-position':$(".sf-menu li.last > a").parent().width()+'px 0'})
		.parent()
		.css({'width':$(".sf-menu li.last").width()+roundedCornerWidth+'px'});
	
	// remove rounded corner of last element in main menu on mouse out
	$(".sf-menu li.last").hover( function() {
		$(".sf-menu li.last > a").css({'background-position':$(".sf-menu li.last").width()-roundedCornerWidth+'px -'+mainMenuHeight+'px'});
	}, function() {
		if( ! $(this).hasClass('sfHover') && ! $(this).hasClass('current') ) {
			$(".sf-menu li.last > a").css({'background-position':$(".sf-menu li.last").width()-roundedCornerWidth+'px 0'});
		} 
	});
	function removeRoundedCorner() {
		if( ! $(".sf-menu > li:last").hasClass('sfHover') && ! $(".sf-menu > li:last").hasClass('current') ) {
			$(".sf-menu li.last > a").css({'background-position':$(".sf-menu li.last").width()-roundedCornerWidth+'px 0'});
		}
	}
	
	if( $(".sf-menu > li:last").hasClass('current') )
		$(".sf-menu li.last > a").css({'background-position':$(".sf-menu li.last").width()-roundedCornerWidth+'px -'+mainMenuHeight+'px'});
	
	
	// reposition last ul to ensure positioning of subnavi to the right border of content area
	if( $(".sf-menu > li:last > ul").width() > $(".sf-menu > li:last").width() ) {
		$(".sf-menu > li:last > ul").css( 'left', $(".sf-menu > li:last").width()-$(".sf-menu > li:last > ul").width() );
	} else {
		$(".sf-menu > li:last > ul").width( $(".sf-menu > li:last > ul").width()+roundedCornerWidth );
	}
	
	// center text vertically in main menu
	$('ul.sf-menu > li > a').each( function() {
		// increase padding for ie6
		var offset = ( $.browser.msie && parseInt($.browser.version) < 8 ) ? 6 : 0;
		
		// set padding
		$(this).css({'padding-top':$(this).parent().parent().height()/2-$(this).height()/2+offset/2+'px'});
		$(this).css({'padding-bottom':$(this).parent().parent().height()/2-$(this).height()/2+offset/2+'px'});
	});
	//}).parent().parent().parent().css('visibility', 'visible');

   // don't highlight main navi on dropdown hover
   $('#tia-navi > .sf-menu > li > ul').hover( function() {
      $(this)
         .prev('a')
         .addClass('tia-keep-highlighted');
   }, function() {
      $(this)
         .prev('a')
         .removeClass('tia-keep-highlighted');
   });

	
	/**
	 * banner rotation in sidebar
	 * uses cycle plugin, see http://malsup.com/jquery/cycle/
	 */
	$('.tia-banner-rotate > div')
		.cycle({fx:      'scrollLeft', 
				   speed:    500, 
				   timeout:  3500 
		});
	
	
	/**
	 * Form styling (do it before accordion generation!)
	 */
   transformForms();
   function transformForms() {
      if( $('*').is('form.jqtransform') ) {

         $("form.jqtransform").each( function(i) {
            $("form.jqtransform").eq(i).jqTransform();
            $("form.jqtransform").eq(i).attr('id', 'submitform-'+i);
            // UPDATE VOTING CAPTCHA, v2
            $("form.jqtransform").eq(i).find('.submitBtn').bind('click', function(evt) {
               evt.preventDefault();
               if(! $(this).hasClass('recaptcha')) {
                  if( checkCaptcha($("form.jqtransform").eq(i)) ) {
                     if( $(this).parents('.tia-voting-form').length > 0 ) {
                        $.cookie('TIAvote', $('.tia-slideshow .active-slide').attr('id'), { path: '/' });
                     }
                     $("form.jqtransform").eq(i).submit();
                  }
               } else {
                     if( $(this).parents('.tia-voting-form').length > 0 ) {
                        $.cookie('TIAvote', $('.tia-slideshow .active-slide').attr('id'), { path: '/' });
                     }
                     $("form.jqtransform").eq(i).submit();
               }
            });
            // UPDATE VOTING CAPTCHA, v2
            if( $('*').is('div.comingas') ) {
               $("form.jqtransform").eq(i).find('div.comingas label:first').css('width', '160px');
               $("form.jqtransform").eq(i).find('div.comingas > div')
                  .eq(3)
                  .css({'clear':'left', 'margin-left':'194px'});
            }
         });
         if( $('*').is('div.media') ) {
            $('div.media').css('width', '260px');
            $('div.media div')
               .css('width', '85px')
               .find('label')
               .css( {'float':'left', 'padding-left':'3px'})
               .end()
               .eq(3)
               .css({'clear':'left'});
         }
         if( $('*').is('div.orderelement') ) {
            $('.orderelement-plus').live( 'click', function(evt) {
               evt.preventDefault();
               var itemContainer = $("form.jqtransform div.orderelement > div:eq(1)");
               var addItem = true;
               var valueToAdd = $(this).children('a').attr('title');
               $(itemContainer).children('input').each(function() {
                  if ($(this).val() == valueToAdd)
                     addItem = false;
               });
               if (addItem) {
                  $(itemContainer).append('<input type="text" name="items" readonly="readonly" value="' + valueToAdd + '" />');
                  $(itemContainer).parent().height($(itemContainer).height());
               }
            });
            $('.orderelement input').live('click', function(evt) {
               $(this).remove();
            });
         }

      }
      if( $('*').is('form.jqtransform-lightbox') ) {
         $("form.jqtransform-lightbox").jqTransform();
         $("form.jqtransform-lightbox .submitBtn").bind('click', function(evt) {
            evt.preventDefault();
            if( checkCaptcha($("form.jqtransform-lightbox").eq(0)) ) {
               $("form.jqtransform-lightbox").submit();
            }
         });
      }
   }

	/**
	 * accordion
	 * uses jQuery UI, see http://jqueryui.com/home
	 */
	if( isAccordion == true ) {
		$("#tia-accordion").accordion({autoHeight: false,
										clearStyle: false,
										fillSpace: false,
										collapsible: true,
										active: ( $('a[name]').index( $('a[name='+window.location.hash.substring(1)+']') ) > 0 ) ? $('a[name]').index( $('a[name='+window.location.hash.substring(1)+']') ) : accordionDefaultId,
										// animated: false,
										icons: {'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus'}
									 });
	} else {
		$('.accordion-header').css({'background'		:	'none',
									 'padding-left'		:	'0'
								   });
	}
	
	/**
	 * Ajax functionality
	 */
	var onloadIndex = 1;
	
	if( $('*').is('.tia-entries') && $('.tia-slideshow:first').hasClass('album') ) {
		ajaxCallBySlideshow( '.album', '.tia-entries' );
	}
	if( $('*').is('.tia-videos') && $('.tia-slideshow:first').hasClass('album') ) {
		ajaxCallBySlideshow( '.album', '.tia-videos' );
	}
	if( $('*').is('.tia-albums') && $('.tia-slideshow:first').hasClass('album') ) {
		ajaxCallBySlideshow( '.album', '.tia-albums' );
	}
	if( $('*').is('.tia-rent') && $('.tia-rent > .tia-slideshow').length > 0 ) {
		ajaxCallBySlideshow( '.panes > div:first .tia-rent > .tia-slideshow', '.panes > div:first .tia-rent > .tia-content-el', '.tia-rent > .tia-content-el' );
	}
	
	// loads finalist entry via ajax when slideshow image is clicked
	function ajaxCallBySlideshow( controller, container, selector ) {
		// get cmsId if set as url param
		var cmsId = GET('cmsId');
		cmsId = ( cmsId != 'undefined' ) ? cmsId : false;
		cmsId = ( $(controller).find('.active-slide').attr('id') != undefined ) ? $(controller).find('.active-slide').attr('id') : cmsId;
		onloadIndex = resolveCmsId( cmsId, controller ) ;
		selector = ( typeof(selector)=='undefined' ) ? container : selector;
		$(container).load( $(controller + ' .tia-slide:eq('+onloadIndex+') a').attr('href') + ' ' + selector + ' > *', function(data, textStatus) {
            onAjaxUpdate( container, data );
				// Update 2011
				if( location.hash.indexOf('finalist') > -1 ) {
						$('a#scroll-to-finalist').trigger('click');
				  }
				if( location.hash.indexOf('votenow') > -1 ) {
						$('a#scroll-to-voting').trigger('click');
				  }
				// End Update 2011
		});
		
		// highlight slide on tab change (relevant for "Rent a piece"/.tia-rent)
		if( $(controller).find('.active-slide').attr('id') == undefined ) {
			setActiveSlide( $(controller + ' .tia-slide:nth(0)').attr('id') );
		}
		
		$(controller + ' .tia-slide a').live('click', function(evt) {
            evt.preventDefault();
				// Update 2011
				// reset hash to avoid scrolling down to votenow when slideshow image is clicked
				if( location.hash.indexOf('votenow') > -1 ) location.hash = '';
				// End Update 2011
            //$(controller + ' .tia-slide .tia-transp-layer').show();
				$(container).load($(this).attr('href') + ' ' + selector + ' > *', function(data) {
            	onAjaxUpdate( container );
					// Update 2011
					$('#scroll-to-finalist').trigger('click');
					// End Update 2011
            });
            
            activeSlideCmsId = $(this).parent().attr('id');
            setActiveSlide( activeSlideCmsId );
            
				// Update 2011
				
				
				// End Update 2011
				
            return false;
        });
	}
	
	function setActiveSlide( slideId ) {
		if( slideId ) {
			//console.log($(mycarousel_itemList[0][1]));
			$('#'+slideId).parents('.tia-slideshow').find('.tia-slide').removeClass('active-slide');
			$('#'+slideId).parents('.tia-slideshow').find('.tia-transp-layer').show();
			$('#'+slideId).addClass('active-slide').find('.tia-transp-layer').hide();
		}
	}
	
	function onAjaxUpdate( container ) {
		  setLinkParams(container);
        transformForms();
        initCarousel( container );
        initLightboxes();
        initFlash();
        $('.jcarousel-control').attr('class', 'jcarousel-control');
        initScrollpane();
        addAjaxLoader( container );
        if( $('*').find('.captcha') ) refreshCaptcha( $('.captcha') );
		  activateScrollTo(900);
		  
	}
	
	function setLinkParams(container) {
	    var currentCountry = $('#varCountry').val();
	    var currentLanguage = $('#varLanguage').val();
	    var destination = $('#varDestination').val();

	    if (env == 'global') {
		    $.each($(container).find('a[href^=/]'), function() {
		    	var url = $(this).attr('href');
		    	var urlHash = '';
		    	if (url.indexOf('#') != -1) {
		    		urlHash = url.substring(url.indexOf('#'), url.length);
		    		url = url.substring(0, url.indexOf('#'));
		    	}
		    	if (url.indexOf('?') == -1)
		    		$(this).attr('href', url + '?pro=' + currentCountry + '&loc=' + currentLanguage + '&dest=' + destination + urlHash);
				else
					$(this).attr('href', url + '&pro=' + currentCountry + '&loc=' + currentLanguage + '&dest=' + destination + urlHash);
		    });
	    }	
	}
	
	function resolveCmsId( cmsId, controller ) {
		var onloadindex = ( $(controller + ' .tia-slide[id='+cmsId+']').length == 1 ) ? $(controller + ' .tia-slide').index( $(controller + ' .tia-slide[id='+cmsId+']') ) : 0;
		return onloadindex;
	}
	
	function addAjaxLoader( container ) {
		$(container)
			.prepend('<div class="tia-loading"><div><img src="'+pathIMG+'tia/img/ajax-loader.gif'+'" /></div></div>')
			.find('.tia-loading')
			.css({
				'position'		:		'absolute',
				'width'			:		'100%',
				'height'		:		$(container).height()+'px',
				'display'		:		'none',
				// 'background'	:		'#000',
				'z-index'		:		'500'
				})
			.bind('ajaxStart', function() {
					$(this).parent().children().not('.tia-loading').fadeOut();
					$(this).show();
        		})
        	.bind('ajaxComplete', function() {
					$(this).fadeOut();
					$(this).parent().children().not('.tia-loading').fadeIn();
				})
			.find('div')
			.css({
				'position'		:		'relative',
				'top'			:		'0',
				'left'			:		'0',
				'width'			:		'24px',
				'margin'		:		'88px auto 0 auto'
				});
	}
	
	
	var mycarousel_itemList = new Array();
	var activeSlideId = onloadIndex;
	var activeSlideCmsId = GET('cmsId');
	var minImagesForSlideshow = 3;
	initCarousel();
	function initCarousel( container ) {
		// new positioning of slides
      $('.tia-slide-img').wrapInner('<div />');
      
		var container = ( typeof(container) != 'undefined' ) ? container : '#tia-wrap';
		jQuery(container + " .tia-slideshow").each( function(i) {
			if( container ==  '#tia-wrap' ) {
				mycarousel_itemList[i] = $(container + " .tia-slideshow").eq(i).find('ul > li');
				$(container + " .tia-slideshow").eq(i).attr('id', 'tia-slideshow-'+i);
				itemListLength = mycarousel_itemList[i].length;
			} else {
				mycarousel_itemList[i+1] = $(container + " .tia-slideshow").eq(i).find('ul > li');
				$(container + " .tia-slideshow").eq(i).attr('id', 'tia-slideshow-'+(i+1));
				itemListLength = mycarousel_itemList[i+1].length;
			}
			// hide prev/next buttons if we got only 3 or less images
			//if( mycarousel_itemList[i].length <= 3 && $(container + " .tia-slideshow").eq(i).hasClass('album') ) {
			minImagesForSlideshow = ( $(container + " .tia-slideshow").eq(i).parent().hasClass('tia-rent') ) ? 4 : 3;
			minImagesForSlideshow = ( $(container + " .tia-slideshow").eq(i).parent().hasClass('content-gallery') ) ? 1 : minImagesForSlideshow;
			minImagesForSlideshow = ( $(container + " .tia-slideshow").eq(i).parent().hasClass('tia-albums') ) ? 1 : minImagesForSlideshow;
			if( itemListLength <= minImagesForSlideshow ) {
				nextButton = '';
				prevButton = '';
			} else {
				nextButton = ( ! $(container + " .tia-slideshow").eq(i).parent().parent().hasClass('.tia-wallpapers') ) ? '<div><img src="'+pathIMG+'tia/img/slideshow_next.gif" /></div>' : '';
				prevButton = ( ! $(container + " .tia-slideshow").eq(i).parent().parent().hasClass('.tia-wallpapers') ) ? '<div><img src="'+pathIMG+'tia/img/slideshow_prev.gif" /></div>' : '';
			}
			
			startSlide = ( ! $(container + " .tia-slideshow").eq(i).parent().hasClass('.tia-albums') && ! $(container + " .tia-slideshow").eq(i).parent().hasClass('content-gallery') ) ? activeSlideId : 1;
			if( ! $(container + " .tia-slideshow").eq(i).parent().hasClass('.tia-albums') ) {
				if( activeSlideId==2 ) {
					if( mycarousel_itemList[i].length == 3 && $(container + " .tia-slideshow").eq(i).hasClass('album') ) {
						startSlide = 1;
					}
				}
			}
			if( $(container + " .tia-slideshow").eq(i).parent().hasClass('content-gallery') ) {
				startSlide = 1;
				activeSlideId = 0;
			}
			
			
			$(container + " .tia-slideshow").eq(i).jcarousel({
		        start: startSlide,
				//start: 1,
				scroll: 1,
		        initCallback: mycarousel_initCallback,
		        buttonNextHTML: nextButton,
		        buttonPrevHTML: prevButton,
		        wrap: 'circular',
		        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
		        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
		        itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback, onAfterAnimation:mycarousel_itemLoadCallback}
		    });
			
			// if first slide shall be loaded we need to copy the last slide to index=0 to fill the gap...
			if( ! $(container + " .tia-slideshow").eq(i).parent().hasClass('tia-albums') && ! $(container + " .tia-slideshow").eq(i).parent().hasClass('content-gallery') ) {
				if( activeSlideId==0 ) {
					if( mycarousel_itemList[i].length <= 3 && $(container + " .tia-slideshow").eq(i).hasClass('album')  ) {
						//$(container + " .tia-slideshow").eq(i).find('.jcarousel-list > li:first').remove();
						$(container + " .tia-slideshow").eq(i).find('.jcarousel-list > li:first').hide();
					} else {
						$(container + " .tia-slideshow").eq(i).find('.jcarousel-list > li:first').html( $(container + " .tia-slideshow").eq(i).find('.jcarousel-list > li:last').html() );
						$(container + " .tia-slideshow").eq(i).find('.jcarousel-list > li:last').remove();
					}
				}
				
			}
			
			// image loading only if necessary
			if( mycarousel_itemList[i].length > 4 ) { 
				var imgSelector = ( $('*').is('.tia-albums') ) ? ".tia-slide img" : ".tia-slide a img";
				$(container + " .tia-slideshow").eq(i).find(imgSelector).each(function(i) {
					if( ! $(container + " .tia-slideshow").eq(i).parent().hasClass('.tia-albums') && ! $(container + " .tia-slideshow").eq(i).parent().hasClass('content-gallery') ) {
						if(i<(activeSlideId-1) || i>(activeSlideId+3)) $(this).addClass('not-shown');
					} else {
						if(i>3) $(this).addClass('not-shown');
					}
				});
				$(container + " .tia-slideshow").eq(i).find(imgSelector+'[class=not-shown]').lazyload({         
				    placeholder 	: 		pathIMG+"tia/img/ajax-loader.gif",
				    event			:		'showimages'
				});
			}
			
			// set placeholders if slide higher than the first three is initial slide
			if( activeSlideId >= 3 && ! $(container + " .tia-slideshow").eq(i).parent().hasClass('tia-albums') ) {
				$(container + " .tia-slideshow")
					.eq(i)
					.find('.jcarousel-list > li:lt('+(activeSlideId-1)+')')
					.each( function(k) {
						$(this).replaceWith('<li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-'+(k+1)+' jcarousel-item-'+(k+1)+'-horizontal jcarousel-item-placeholder jcarousel-item-placeholder-horizontal"></li>');
					});					
			}
			
			// position content of slides
			//positionSlideContent();
			
		});

      $('.jcarousel-control > a > img').each( function() {
         $(this).load( function() {
            if( $(this).height() < $(this).parent().height() ) {
               $(this).css({'top':($(this).parent().height()/2-$(this).height()/2)+'px', 'position':'relative'});
            }
         });
      });
	}

   
	
	
	function mycarousel_initCallback(carousel, state) {
		jQuery('#'+carousel.container.attr('id')+' .jcarousel-control a').bind('click', function() {
	        $('#'+carousel.container.attr('id')+' .jcarousel-control a').removeClass('active-pic');
			  carousel.scroll(jQuery.jcarousel.intval($('#'+carousel.container.attr('id')+' .jcarousel-control a').index($(this))+1));
	        $('a.active-pic div').appendTo($(this));
	        $(this).attr('class', 'active-pic');
	        return false;
	    });
		
		jQuery('.jcarousel-scroll select').bind('change', function() {
	        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
	        return false;
	    });
		
	    jQuery('.jcarousel-next').bind('click', function() {
	    	// set active slide for highlighting
			//setActiveSlide( activeSlideCmsId );
	    	return false;
	    });

	    jQuery('.jcarousel-prev').bind('click', function() {
	    	// set active slide for highlighting
			//setActiveSlide( activeSlideCmsId );
	    	return false;
	    });
	    
	    
	};
	
	function mycarousel_itemLoadCallback(carousel, state) {
		activeSlideCmsId = ( activeSlideCmsId == 'undefined' ) ? $('#'+carousel.container.attr('id')).find('.tia-slide').eq(0).attr('id') : activeSlideCmsId;
		//setActiveSlide( activeSlideCmsId );
		//console.log(mycarousel_itemList[0]);
		return true;
	}
	
	function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {

		// add clones of elements to ensure an infinite loop
		var idx = carousel.index(i, mycarousel_itemList[carousel.container.attr('id').substr(14)].length);
		minImagesForSlideshow = ( $("#tia-slideshow-"+i).parent().hasClass('tia-rent') ) ? 4 : 3;
		minImagesForSlideshow = ( $("#tia-slideshow-"+i).parent().hasClass('content-gallery') ) ? 1 : minImagesForSlideshow;
		minImagesForSlideshow = ( $("#tia-slideshow-"+i).parent().hasClass('tia-albums') ) ? 1 : minImagesForSlideshow;
		if( $(".tia-slideshow").eq(carousel.container.attr('id').substr(14)).hasClass('album') || 
			$(".tia-slideshow").eq(carousel.container.attr('id').substr(14)).parent().hasClass('tia-rent') ||
			$(".tia-slideshow").eq(carousel.container.attr('id').substr(14)).parent().hasClass('home')) {
			if( mycarousel_itemList[carousel.container.attr('id').substr(14)].length > minImagesForSlideshow ) {
				var el = carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[carousel.container.attr('id').substr(14)][idx - 1]));
			} else {
				if( activeSlideCmsId ) {
					$(".tia-slideshow").eq(carousel.container.attr('id').substr(14)).find('.tia-transp-layer').show();
					$('#'+activeSlideCmsId).addClass('active-slide').find('.tia-transp-layer').hide();
				}
			}
		} else {
			var el = carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[carousel.container.attr('id').substr(14)][idx - 1]));
		}
		
		// load image on request
		var imgSelector = ( $('*').is('.tia-albums') ) ? ".tia-slide img" : ".tia-slide a img";
		var curItem = carousel.get(i);
		// replace preload image if necessary
		if( curItem.find(imgSelector).attr("original") != curItem.find(imgSelector).attr("src") ) {
			curItem.find(imgSelector).attr("src", curItem.find(imgSelector).attr("original"));
		}	
		
		// set border in album gallery
		if( $('#'+carousel.container.attr('id')).find('.jcarousel-control').length > 0 ) {
			$('#'+carousel.container.attr('id')+' .jcarousel-control a').removeClass('active-pic').eq(idx-1).addClass('active-pic').append('<div></div>');
		}	
		
		// center image on load
		/*if( curItem.find(imgSelector) != 'undefined' ) {
         var $image = curItem.find(imgSelector);
         if($image.length > 0 && $image[0].complete) {
            positionSlideContentOnRequest($image, carousel.container.attr('id'));
         } else {
            $image.load(function() {
               positionSlideContentOnRequest($image, carousel.container.attr('id'));
            });
         }
      }*/
	};

	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
		// make sure that lightbox links still work
		initLightboxes();
		
		// scroll to active thumbnail pic
		if( $('#'+carousel.container.attr('id')).find('.jcarousel-control').length > 0 ) {
			var imgCountPerRow = 4;
			var row = Math.ceil(($('#'+carousel.container.attr('id')+' .jcarousel-control a').index( $('#'+carousel.container.attr('id')+' .jcarousel-control a.active-pic') )+1)/imgCountPerRow)-1;
			$('#'+carousel.container.attr('id')+' .jcarousel-control')[0].scrollTo( $('#'+carousel.container.attr('id')+' .jcarousel-control a.active-pic img').height()*(row) );
		}
		
		// remove redundant elements
		carousel.remove(i);
		
		
		
	};
	
	function mycarousel_getItemHTML(item) {
		if( ! $('*').is('.home') ) {
			$(item).find('.active-slide').removeClass('active-slide').find('.tia-transp-layer').show();
			if( $(item).find('.tia-slide').attr('id') == activeSlideCmsId && activeSlideCmsId != '' ) {
				$(item).find('.tia-slide').addClass('active-slide').find('.tia-transp-layer').hide();
			}
		}
		return $(item).html();
	};
	
	
	function positionSlideContent() {
		return true;
      /*$('.content-gallery .tia-slide').each( function(i) {
			//$('.content-gallery .tia-slide').eq(i).find('img').hide();
			$('.content-gallery .tia-slide').eq(i).find('img').load( function() {
				var curImg = $('.content-gallery .tia-slide').eq(i).find('img');
				var container = $('.content-gallery .tia-slide').eq(i).parent();
				if( curImg.height() < container.height() ) {
					curImg
                  .parents('.tia-slide')
                  .css({'top':(container.height()/2-curImg.height()/2)+'px', 'position':'relative'});
				}
				//$('.content-gallery .tia-slide').eq(i).find('img').show();
			});
		});
		$('.home .tia-slide').each( function(i) {
			var curImg = $('.home .tia-slide').eq(i).find('img:first');
			var container = $('.home .tia-slide').eq(i).parent();
			if( curImg.height() < container.height() ) {
				curImg
               .css({'top':(container.height()/2-curImg.height()/2)-10+'px', 'position':'relative'});
			}
		});
		$('.tia-rent .tia-slide').each( function(i) {
			var curImg = $('.tia-rent .tia-slide').eq(i).find('img:first');
			var container = $('.tia-rent .tia-slide').eq(i).find('a:first');
			if( curImg.height() < container.height() ) {
				curImg
               .css({'padding-top':(container.height()/2-curImg.height()/2)+'px', 'position':'relative'});
			}
		});
      $('.album .tia-slide').each( function(i) {
			var curImg = $('.album .tia-slide').eq(i).find('img:first');
			var container = $('.album .tia-slide').eq(i).find('a:first');
			if( curImg.height() < container.height() ) {
				curImg
               .css({'top':(container.height()/2-curImg.height()/2)+'px', 'position':'relative'});
			}
		});*/
	}
	function positionSlideContentOnRequest( imgSelector, container ) {
		
		return true;
      var curImg = imgSelector;
      if( imgSelector.parents('.tia-slideshow').parent().hasClass('.content-gallery') ) {
			container = $('#'+container);
         if( curImg.height() < container.height() ) {
				curImg
               .parents('.tia-slide')
               .css({'top':(container.height()/2-curImg.height()/2)+'px', 'position':'relative'});
			}
			if( curImg.height() >= container.height() ) {
				curImg
               .parents('.tia-slide')
               .css({'top':'0', 'position':'relative'});
			}
			// quick & dirty hack for klick dummy - change in live version!
			if( curImg.height() <= 24 ) {
				curImg
               .parents('.tia-slide')
               .css({'top':'0', 'position':'relative'});
			}
			// end of hack
		}
      if( imgSelector.parents('.tia-slideshow').hasClass('.album') ) {
         container = $('#'+container + " .tia-slide > a:first");
         if( curImg.height() < container.height() ) {
				curImg
               .css({'top':(container.height()/2-curImg.height()/2)+'px', 'position':'relative'});
			}
			if( curImg.height() >= container.height() ) {
				curImg
               .css({'top':'0', 'position':'relative'});
			}
		}
      if( imgSelector.parents('.tia-slideshow').parent().hasClass('.tia-rent') ) {
         container = $('#'+container + " .tia-slide > a:first");
         if( curImg.height() < container.height() ) {
				curImg
               .css({'padding-top':(container.height()/2-curImg.height()/2)+'px', 'position':'relative'});
			}
			if( curImg.height() >= container.height() ) {
				curImg
               .css({'top':'0', 'position':'relative'});
			}
		}
      if( imgSelector.parents('.tia-slideshow').parent().hasClass('.home') ) {
         container = $('#'+container + " .tia-slide > a:first");
         if( curImg.height() < container.height() ) {
				curImg
               .css({'padding-top':(container.height()/2-curImg.height()/2)+'px', 'position':'relative'});
			}
			if( curImg.height() >= container.height() ) {
				curImg
               .css({'top':'0', 'position':'relative'});
			}
		}
	}

   

	// hover effect for galleries
	$('.gallery div.tia-slideshow .jcarousel-item').live( 'mouseover', function() {
		$(this).find('.tia-transp-layer').css('visibility', 'hidden');
	});
	$('.gallery div.tia-slideshow .jcarousel-item').live( 'mouseout', function() {
		$(this).find('.tia-transp-layer').css('visibility', 'visible');
	});
	
	$('.gallery div.album .jcarousel-item a').click( function(e) {
		//e.preventDefault();
	});
	$('.gallery div.album .jcarousel-item').click( function(e) {
		//$('#tia-ajax-wrapper').load($(this).find('a:first').attr('href'));
	});
	
	//setActiveSlide();
	
	$('.album .tia-slide > a').live( 'click', function(e) {
		/*e.preventDefault();
		$('.tia-albums .tia-dynamic-slideshow, .tia-wallpapers .tia-dynamic-slideshow').replaceWith( '<div class="tia-dynamic-slideshow"><a href="'+$(this).attr('href')+'"></a></div>' );
		dynamiccarousel_itemList = new Array();
		imgAr = new Array();
		initDynamicSlideshow();*/
	});
	
	/**
	 * init scroll pane for album galleries
	 */
	
	function initScrollpane() {
		
		//if( $('.jcarousel-control > a').length > 1 ) {
			// don't show scrollbar if we got only 2 rows
			if( $('.jcarousel-control > a').length > 4 && $('.jcarousel-control > a').length < 9 ) {
				$('.jcarousel-control').height( $('.jcarousel-control').height()+10 );
			}
			$('.jcarousel-control').jScrollPane( {
				'scrollbarWidth'	:	15,
				'scrollbarMargin'	:	0,
				'showArrows'		:	true,
				'arrowSize'			:	23,
				'dragMaxHeight'		:	15,
				'animateTo'			:	true
			}).find('a.active-pic').prepend('<div></div>');
			
		/*} else {
			
			$('.jcarousel-control').find('a.active-pic').prepend('<div></div>');
		}*/
	}
	
	/**
	 * page navi inside accordion
	 */

     $('.tia-inner-page-navi').each(function(i) {
        var pages = $(this).find('.tia-inner-page');
        var container = $(this);
        var pager = $('#tia-pager-'+i);
        var next = $('#next-'+i);
        var prev = $('#prev-'+i);
        var page = 1;
        
        var showPage = function(i) {

            if (i > 1)
                prev.css('visibility', 'visible');
            else
                prev.css('visibility', 'hidden');
            
            if (i >= (pages.length-1))
                next.css('visibility', 'hidden');
            else
                next.css('visibility', 'visible');
            

            pages.hide();
            pager.find('a').removeClass('activeSlide');
            pages.eq(i-1).show(); 
            pager.find('a[rel='+i+']').addClass('activeSlide');
        };
        pages.not(':first').hide();
        
        if (pages.length-1 == 1) {
            next.css('visibility', 'hidden');
        }
        
        
        for (var j=0; j < pages.length; j++) {
            var pagelink = $('<li class="border"><a href="#" rel="'+(j+1)+'">'+(j+1)+'</a></li>');
            
            pagelink.click(function() {
                 pages.hide();
                 pager.find('a').removeClass('activeSlide');
                 
                 var i = $(this).find('a').addClass('activeSlide').attr('rel');
                 showPage(i);
                 
            });
            
            if (j==0) pagelink.find('a').addClass('activeSlide');
                                  
            pager.append(pagelink);
        }
        
        
        next.click(function() {
            page++;
            if (page > pages.length) page = pages.length;
            
            showPage(page);
        });

        prev.click(function() {
            page--;
            if (page < 1) page = 1;

            showPage(page);
        });
         
     });
        
      // $('.tia-inner-page-navi').each( function(i) {
      //      $('.tia-inner-page-navi').eq(i).cycle({ 
      //             fx:      'scrollHorz', 
      //             speed:    500, 
      //             timeout:  0,
      //             pager:  '#tia-pager-'+i,
      //             next: '#next-'+i,
      //             prev: '#prev-'+i,
      //             pagerAnchorBuilder: pagerFactory,
      //             after: stylePager
      //         });
      //  });
         
	function pagerFactory(idx, slide) {
		//var s = idx > 2 ? ' style="display:none"' : '';
        //return '<li'+s+' class="border"><a href="#">'+(idx+1)+'</a></li>';
		return '<li class="border"><a href="#">'+(idx+1)+'</a></li>';
    };
    
    if( ! $('*').is('.tia-lightbox-vote-for') && ! $('*').is('.tia-lightbox-voted') ) {
    	stylePager();
    }
    $('.prev').css('visibility', 'hidden');
	function stylePager(currSlideElement, nextSlideElement, options, forwardFlag) {
		
		$('.tia-pager').each( function(i) {
			// remove border from last pager
			$('.tia-pager').eq(i).find('li:last').removeClass('border');
		});
		
		// show/hide prev/next links
		if( options ) {
			if( $(this).parent().find('.tia-inner-page').index(this) == $(this).parent().children().length-1 ) {
				$(options.next).css('visibility', 'hidden');
			} else {
				$(options.next).css('visibility', 'visible');
			}
			if( $(this).parent().find('.tia-inner-page').index(this) == 0 ) {
				$(options.prev).css('visibility', 'hidden');
			} else {
				$(options.prev).css('visibility', 'visible');
			}
		}
		
		// make sure that lightbox links still work
		initLightboxes();
	}
	
	
	/**
	 * embed flash movies
	 * uses swfobject
	 */
	initFlash();
	function initFlash() {
		$('div.tia-flash-movie').each( function(i) {
	    	var minFlashVersion = 8;
	        var flashVersion = swfobject.getFlashPlayerVersion();
	        var flashHeight = parseInt($(this).parent().css('height'));
	        var flashWidth = parseInt($(this).parent().css('width'));
	        var fileUrl = $(this).find('a').attr('href');
	        fileUrl = fileUrl.substring(0, fileUrl.indexOf('?'));
	        $(this).attr('id', 'tia-flash-movie-'+i);
	        flashvars = {
	            file: fileUrl,
	            //file: 'http://content.longtailvideo.com/videos/flvplayer.flv',
	            width: flashWidth,
	            height: flashHeight,
	            image: $(this).find('img').attr('src')
	         };
	         params = {
	            scale: 'noscale',
	            wmode: 'transparent',
	        	allowfullscreen: 'true',
	            allowscriptaccess: 'always'
	         };
	         attributes = {};
	         if (flashVersion.major >= minFlashVersion) {
	             swfobject.createCSS("div.tia-noflash-msg", "display: none");
	             swfobject.embedSWF(pathPLAYER+"mplayer/player-licensed.swf", $(this).attr('id'), flashWidth, flashHeight, "7.0.14", "", flashvars, params, attributes);
	         } else {
	        	 swfobject.createCSS("div.tia-flash-movie img", "display: none");
	         }
	    });
	}
	
	if( isAccordion == true ) {
		$("#tia-accordion-dynamic").accordion({autoHeight: false,
			clearStyle: false,
			fillSpace: false,
			collapsible: true,
			active: ( $('a[name]').index( $('a[name='+window.location.hash.substring(1)+']') ) > 0 ) ? $('a[name]').index( $('a[name='+window.location.hash.substring(1)+']') ) : accordionDefaultId,
			icons: {'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus'}
		});
	} else {
		$('.accordion-header').css({'background'		:	'none',
			 						 'padding-left'		:	'0'
		 						   });
	}
	
	// add teaserlink GET Param to sidebar links, triggers iframe to open on page load
	$('#tia-sidebar .tia-teaser a, #tia-motto a, .tia-news-text a').each( function(i) {
    	var url = $(this).attr('href');
		if (typeof(url) != 'undefined') {
	    	var urlHash = '';
	    	if (url.indexOf('#') != -1) {
	    		urlHash = url.substring(url.indexOf('#'), url.length);
	    		url = url.substring(0, url.indexOf('#'));
	    	}
			if( url.indexOf('?') == -1) {
				$(this).attr('href', url + '?teaserlink=1' + urlHash);
			} else {
				$(this).attr('href', url + '&teaserlink=1' + urlHash);
			}
		}
	});
	
	/**
	 * lightboxes for image zoom
	 * uses plugin Fancybox, see http://fancybox.net/home
	 */
	initLightboxes();
		
	function initLightboxes() {
		$("a.lightbox").fancybox({
			'padding'       :   10,
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	400, 
			'speedOut'		:	200, 
			'overlayShow'	:	true,
			'overlayOpacity':   0.8,
			'overlayColor'  :   '#000',
			'centerOnScroll':   true,
			'cyclic'        :   true
		});
		$('a.iframe').fancybox({
			'transitionIn'	:	'fade',
			'transitionOut'	:	'fade',
			'padding'       :   10,
			'width'         :   716,
			'height'        :   566,
			'overlayShow'	:	true,
			'overlayOpacity':   0.8,
			'overlayColor'  :   '#000',
			'centerOnScroll':   false,
			'cyclic'        :   true,
			'type'          :   'iframe',
			'scrolling'     :   'no',
			'autoScale'     :   false,
			'onStart'       :   function() { 
									$('#fancybox-close').css({'top':'10px', 'right':'15px'});
									$('body').height( $(document).height() );
								},
			'onComplete'    :   function() {
									$('#fancybox-inner').css('display', 'block');
								},
			'changeFade'	:   300
		});
		
		$('a.iframe-parent').click( function(e) {
			e.preventDefault();
			//alert($(window.parent).find('#tia-wrap'));
			parent.$.fancybox({
				'transitionIn'	:	'fade',
				'transitionOut'	:	'fade',
				'padding'       :   10,
				'width'         :   716,
				'height'        :   566,
				'overlayShow'	:	true,
				'overlayOpacity':   0.8,
				'overlayColor'  :   '#000',
				'centerOnScroll':   false,
				'cyclic'        :   true,
				'type'          :   'iframe',
				'scrolling'     :   'no',
				'autoScale'     :   false,
				'onStart'       :   function() { 
										$('#fancybox-close').css({'top':'10px', 'right':'15px'});
										$('body').height( $(document).height() );
									},
				'onComplete'    :   function() {
										$('#fancybox-inner').css('display', 'block');
									},
				'changeFade'	:   300,
				'href': $(this).attr('href')
			});
		});
		
		// auto open on teaser link
		if( GET('teaserlink') == 1 && $('.tia-prizes a.iframe' ).length > 0 ) {
			$('a.iframe').fancybox({
				'transitionIn'	:	'fade',
				'transitionOut'	:	'fade',
				'padding'       :   10,
				'width'         :   716,
				'height'        :   566,
				'overlayShow'	:	true,
				'overlayOpacity':   0.8,
				'overlayColor'  :   '#000',
				'centerOnScroll':   false,
				'cyclic'        :   true,
				'type'          :   'iframe',
				'scrolling'     :   'no',
				'autoScale'     :   false,
				'onStart'       :   function() { 
										$('#fancybox-close').css({'top':'10px', 'right':'15px'});
										$('body').height( $(document).height() );
									},
				'onComplete'    :   function() {
										$('#fancybox-inner').css('display', 'block');
									},
				'changeFade'	:   300
			}).trigger('click');
		}
		
		$('a.iframe-resize').click( function(e) {
			if( $(this).attr('href') != '#' ) {
				location.href = $(this).attr('href');
			} else {
				e.preventDefault();
				if( $('.tia-prizes').css('display') == 'none' ) {
					$('.tia-prizes').css('display', 'block');
					parent.$.fancybox.resizeIframe($(document).height(), 'close', parseInt($('.tia-img-txt-fullwidth:first').css('height')) );
				} else {
					parent.$.fancybox.resizeIframe( parseInt($('.tia-img-txt-fullwidth:first').css('height')), 'close', parseInt($('.tia-img-txt-fullwidth:first').css('height')) );
					$('.tia-prizes').css('display', 'none');
				}
			}
		});
		if( $('*').is('.tia-lightbox-vote-for') ) {
			parent.$.fancybox.resizeIframe( parseInt($('.tia-img-txt-fullwidth:first').css('height')), 'close', parseInt($('.tia-img-txt-fullwidth:first').css('height')) );
		}
		if( $('*').is('.tia-lightbox-voted') ) {
			parent.$.fancybox.resizeIframe( parseInt($('.tia-img-txt-fullwidth:first').css('height')), 'close', parseInt($('.tia-img-txt-fullwidth:first').css('height')) );
		}
		if( $('*').is('.tia-lightbox-terms') ) {
			parent.$.fancybox.resizeIframe( parseInt($('#tia-inner-content').height()), 'close', 0 );
		}
		if( $('*').is('.tia-lightbox-results') ) {
			parent.$.fancybox.resizeIframe( parseInt($('#tia-inner-content').height()), 'close', 0 );
		}
	}
	
	
	
	$("ul.tabs").tabs("div.panes > div", {
		onClick: function(event, tabIndex) {
			ajaxCallBySlideshow( '.panes > div:nth('+tabIndex+') .tia-rent > .tia-slideshow', '.panes > div:nth('+tabIndex+') .tia-rent > .tia-content-el', '.tia-rent > .tia-content-el' );
		}
	});
	
	
	/**
	 * Country selector
	 */
    var currentCountry = $('#varCountry').val();
    var currentLanguage = $('#varLanguage').val();
    var destination = $('#varDestination').val();

    if (env == 'global') {
	    $.each($('div#tia-main a[href^=/], div#tia-navi a[href^=/], div#tia-close a[href^=/], div#tia-home a[href^=/]'), function() {
	    	var url = $(this).attr('href');
	    	var urlHash = '';
	    	if (url.indexOf('#') != -1) {
	    		urlHash = url.substring(url.indexOf('#'), url.length);
	    		url = url.substring(0, url.indexOf('#'));
	    	}
	    	if (url.indexOf('?') == -1)
	    		$(this).attr('href', url + '?pro=' + currentCountry + '&loc=' + currentLanguage + '&dest=' + destination + urlHash);
			else
				$(this).attr('href', url + '&pro=' + currentCountry + '&loc=' + currentLanguage + '&dest=' + destination + urlHash);
	    });
    }
    
	var tempHtml = '';
	if (currentCountry == 'tia' && (destination == '' || destination == null))
		$('.tia-country-selector ul').prepend('<li><a href="#">INTERNATIONAL</a></li>');
	else {
		if (destination != null && destination != '') {
			countryPath = destination;
			tempHtml = $('.tia-country-selector ul li a[href^=/' + countryPath + '/]').parent().html();
			$('.tia-country-selector ul li a[href^=/' + countryPath + '/]').parent().remove();
			$('.tia-country-selector ul').prepend('<li>' + tempHtml + '</li>');
		} else {
			tempHtml = $('.tia-country-selector ul li a[href^=/' + currentCountry + '/' + currentLanguage + '/]').parent().html();
			$('.tia-country-selector ul li a[href^=/' + currentCountry + '/' + currentLanguage + '/]').parent().remove();
			$('.tia-country-selector ul').prepend('<li>' + tempHtml + '</li>');
		}
    }  
	 
	$('.tia-country-selector').hover( function() {
		$(this).css('border', '1px solid #333');
	}, function() {
		$(this).css('border', '1px solid #000');
	});
	var cSelectHeight = $('.tia-country-selector').height();
	var cSelectMinHeight = '16px';
	var cSelectMaxHeight = '250px';
	$('.tia-country-selector').wrapInner('<div class="tia-country-wrapper"></div>');
	$('.tia-country-selector a').bind('click', function(evt) {
		evt.preventDefault();
		if( $(this).parents('.tia-country-selector').height() > cSelectHeight && $(this).attr('class') ) {
			hideCountrySelect( $(this).parents('.tia-country-selector') );
		} else {
			$(this)
				.parents('.tia-country-selector')
				.stop()
				//.animate( {height: $(this).find('ul').height()+'px', 'border-color': '#333' }, 200 );
				.animate( {'height': cSelectMaxHeight}, 200 )
				.find('.tia-country-wrapper')
				.css({'height':cSelectMaxHeight})
				.jScrollPane({
					'scrollbarWidth'	:	15,
					'scrollbarMargin'	:	0,
					'showArrows'		:	false,
					'arrowSize'			:	0,
					'dragMaxHeight'	:	15,
					'animateTo'			:	false
				});
		}
	});
	$('.tia-country-selector > div > ul > li > a:first').addClass('active');
	
	// $('.tia-country-selector').bind('mouseleave', function() {
	// 	hideCountrySelect( $(this) );
	// });


	$('.tia-country-selector').hoverIntentCustomized({
		over: function(){return true;}
		,out: function() { hideCountrySelect( $(this) ); }
		,timeout: 900
	});

	
	function hideCountrySelect( selDiv ) {
		selDiv
					//.parents('.tia-country-selector')
					.stop()
					.find('.tia-country-wrapper')
					.css({'height':cSelectMinHeight, 'top':'0px'})
					.end()
					.find('.jScrollPaneTrack')
					.css({'visibility':'hidden'})
					.end()
					.animate( {'height': cSelectMinHeight}, 150)
					.css('border-color', '#999999');
		selDiv.find('.tia-country-wrapper').width( selDiv.find('.jScrollPaneContainer').width() );
		selDiv.find('.jScrollPaneContainer').replaceWith( selDiv.find('.tia-country-wrapper') );
	}	
	
	// remove in productive environment
	//$('.tia-country-selector ul li:first').remove();
	// end remove
	
    $('.tia-country-selector ul li a[class!=active]').click(function(evt){
        evt.preventDefault();
        
        var destPath = $(this).attr('href');
        var destCountry = destPath.substring(1, destPath.substring(1, destPath.length).indexOf('/') + 1);
        var destLanguage = destPath.substring(destPath.substring(1, destPath.length).indexOf('/') + 2, destPath.lastIndexOf('/'));
        var destUrl = '/' + destCountry + '/' + destLanguage + '/tiaSiteStructure.js';

        var ajaxResult = null;
        function getTiaSiteStructure(destUrlP) {
			$.ajax({
				async: false,
				url: destUrlP,
				success: function(data){
					try {
						ajaxResult = JSON.parse(data);
					} 
					catch (e) {
						ajaxResult =  null;
					}
				},
				error: function(){
					ajaxResult = null;
				}
			});
        }
        
        getTiaSiteStructure(destUrl);
                if (ajaxResult == null)
                	getTiaSiteStructure('/tia/en/tiaSiteStructure.js');
                if (ajaxResult == null)
                	window.location = '/tia/en/index_tia.html?pro=' + currentCountry + '&loc=' + currentLanguage + '&dest=' + destCountry + '/' + destLanguage
			else {
			destUrl = '';
						for (key in ajaxResult) {
							if (key == pageID) {
								destUrl = ajaxResult[key] + '?pro=' + currentCountry + '&loc=' + currentLanguage + '&dest=' + destCountry + '/' + destLanguage
								break;
							}
						}
						if (destUrl == '' || destUrl == null) 
							if (ajaxResult.index) 
								destUrl = ajaxResult.index + '?pro=' + currentCountry + '&loc=' + currentLanguage + '&dest=' + destCountry + '/' + destLanguage
							else 
								destUrl = '/tia/en/index_tia.html?pro=' + currentCountry + '&loc=' + currentLanguage + '&dest=' + destCountry + '/' + destLanguage
						window.location = destUrl;
			}
    });
	
	
	/**
	 * Loading of certain images on demand 
	 */
	$('.tia-finalists .tia-gallery-img img').lazyload();
	
	/**
	 * Captcha
	 */
	if( $('*').is('.tia-rent') ) {
      //$('a.jqTransformCheckbox').css('background-image', 'url('+pathIMG+'tia/img/jqtransform/checkbox_grey.gif)');
      var capAr = {
    		  img		: 		new Array( pathIMG+'tia/img/captcha_1_grey.jpg', 
										   pathIMG+'tia/img/captcha_2_grey.jpg', 
										   pathIMG+'tia/img/captcha_3_grey.jpg', 
										   pathIMG+'tia/img/captcha_4_grey.jpg', 
						 				   pathIMG+'tia/img/captcha_5_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_6_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_7_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_8_grey.jpg',
					 					   pathIMG+'tia/img/captcha_9_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_10_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_11_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_12_grey.jpg', 
						 				   pathIMG+'tia/img/captcha_13_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_14_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_15_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_16_grey.jpg',
					 					   pathIMG+'tia/img/captcha_17_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_18_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_19_grey.jpg', 
					 					   pathIMG+'tia/img/captcha_20_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_21_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_22_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_23_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_24_grey.jpg', 
		        		 				   pathIMG+'tia/img/captcha_25_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_26_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_27_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_28_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_29_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_30_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_31_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_32_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_33_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_34_grey.jpg', 
		        		 				   pathIMG+'tia/img/captcha_35_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_36_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_37_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_38_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_39_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_40_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_41_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_42_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_43_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_44_grey.jpg', 
		        		 				   pathIMG+'tia/img/captcha_45_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_46_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_47_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_48_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_49_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_50_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_51_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_52_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_53_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_54_grey.jpg', 
		        		 				   pathIMG+'tia/img/captcha_55_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_56_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_57_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_58_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_59_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_60_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_61_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_62_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_63_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_64_grey.jpg', 
		        		 				   pathIMG+'tia/img/captcha_65_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_66_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_67_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_68_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_69_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_70_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_71_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_72_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_73_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_74_grey.jpg', 
		        		 				   pathIMG+'tia/img/captcha_75_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_76_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_77_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_78_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_79_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_80_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_81_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_82_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_83_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_84_grey.jpg', 
		        		 				   pathIMG+'tia/img/captcha_85_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_86_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_87_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_88_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_89_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_90_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_91_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_92_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_93_grey.jpg', 
	        		 					   pathIMG+'tia/img/captcha_94_grey.jpg', 
		        		 				   pathIMG+'tia/img/captcha_95_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_96_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_97_grey.jpg', 
		       		 					   pathIMG+'tia/img/captcha_98_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_99_grey.jpg', 
		     		 					   pathIMG+'tia/img/captcha_100_grey.jpg'
									   ),
			code	:		new Array( 'hgz6wt', 
									   'retwze', 
									   'fgrpe5', 
									   'loijwb', 
									   'kopizh', 
									   'ko98j1', 
									   'pi8zwh', 
									   'w451jn',
									   'snash1', 
					 				   'nuhz34', 
					 				   'asfjuw', 
					 				   '87uhbd', 
					 				   'nuzrte', 
					 				   'drehtr', 
					 				   'lopo9d', 
					 				   'kilkj3', 
					 				   'lok87t', 
					 				   'axmoim', 
					 				   'qkoinv', 
					 				   'hgz2gv',
		       		 				   'JRX10O',
		       		 				   'VQKAPW',
		       		 				   'X3QF06',
		       		 				   '9MAA01',
		       		 				   '2V9Q2V',
		       		 				   'RR1KE1',
		       		 				   'BC08LQ',
		       		 				   'YXRGOE',
		       		 				   'LOBALA',
		       		 				   '20R3SP',
		       		 				   '6D1YRZ',
		       		 				   'ZB316L',
		       		 				   'OVIUKD',
		       		 				   'NHQR53',
		       		 				   'CUB3RX',
		       		 				   '33B2BQ',
		       		 				   'RMLPL3',
		       		 				   '1VE62W',
		       		 				   '8L9ISW',
		       		 				   '2DLGFS',
		       		 				   'ENZDCA',
		       		 				   '99GOWD',
		       		 				   'N3C8MI',
		       		 				   '29JO5E',
		       		 				   'UH9LZ4',
		       		 				   'QRVDQ7',
		       		 				   'RK4MXQ',
		       		 				   'MC55X8',
		       		 				   'RBZL7W',
		       		 				   'NCV034',
		       		 				   'PP3PDJ',
		       		 				   '2ZMS99',
		       		 				   'LTXF7P',
		       		 				   'APVEIA',
		       		 				   'T8HKCP',
		       		 				   'OK8VRS',
		       		 				   '9OI3W2',
		       		 				   'ZNAMAB',
		       		 				   '0HWGD9',
		       		 				   'YX6WKM',
		       		 				   'SI6O7N',
		       		 				   'Q7P5UM',
		       		 				   'ZYVDHO',
		       		 				   '8JVS03',
		       		 				   'L29S48',
		       		 				   'Q9P1M1',
		       		 				   '550EI9',
		       		 				   'LM6OF8',
		       		 				   '19U3BY',
		       		 				   'RO7R7R',
		       		 				   '98C5H8',
		       		 				   'N6KWHY',
		       		 				   '8NKFES',
		       		 				   'EDW22Y',
		       		 				   'WTHQ6L',
		       		 				   'W653RU',
		       		 				   'SSSCYF',
		       		 				   'K6APOL',
		       		 				   'W9TLWR',
		       		 				   'AXD8X5',
		       		 				   '2TX1DP',
		       		 				   'BKUH0D',
		       		 				   'OMQJI0',
		       		 				   'BWKFUT',
		       		 				   '36LJNW',
		       		 				   'BLWQ10',
		       		 				   'CD72L6',
		       		 				   'HOWQPG',
		       		 				   '28KW9M',
		       		 				   'VYUTGK',
		       		 				   'XM14A2',
		       		 				   'JLXR94',
		       		 				   'NM2RF9',
		       		 				   'QCY5J9',
		       		 				   'GQAJ16',
		       		 				   'CY50PK',
		       		 				   'P3MQFY',
		       		 				   'XIPBRT',
		       		 				   'MB3FBN',
		       		 				   '30VUT4'
									)
      };
   } else {
	   var capAr = {
		         img		: 		new Array( pathIMG+'tia/img/captcha_1_grey.jpg',
										   pathIMG+'tia/img/captcha_2_grey.jpg',
										   pathIMG+'tia/img/captcha_3_grey.jpg',
										   pathIMG+'tia/img/captcha_4_grey.jpg',
						 				   pathIMG+'tia/img/captcha_5_grey.jpg',
					 					   pathIMG+'tia/img/captcha_6_grey.jpg',
					 					   pathIMG+'tia/img/captcha_7_grey.jpg',
					 					   pathIMG+'tia/img/captcha_8_grey.jpg',
					 					   pathIMG+'tia/img/captcha_9_grey.jpg',
					 					   pathIMG+'tia/img/captcha_10_grey.jpg',
					 					   pathIMG+'tia/img/captcha_11_grey.jpg',
					 					   pathIMG+'tia/img/captcha_12_grey.jpg',
						 				   pathIMG+'tia/img/captcha_13_grey.jpg',
					 					   pathIMG+'tia/img/captcha_14_grey.jpg',
					 					   pathIMG+'tia/img/captcha_15_grey.jpg',
					 					   pathIMG+'tia/img/captcha_16_grey.jpg',
					 					   pathIMG+'tia/img/captcha_17_grey.jpg',
					 					   pathIMG+'tia/img/captcha_18_grey.jpg',
					 					   pathIMG+'tia/img/captcha_19_grey.jpg',
					 					   pathIMG+'tia/img/captcha_20_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_21_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_22_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_23_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_24_grey.jpg',
		        		 				   pathIMG+'tia/img/captcha_25_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_26_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_27_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_28_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_29_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_30_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_31_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_32_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_33_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_34_grey.jpg',
		        		 				   pathIMG+'tia/img/captcha_35_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_36_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_37_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_38_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_39_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_40_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_41_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_42_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_43_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_44_grey.jpg',
		        		 				   pathIMG+'tia/img/captcha_45_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_46_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_47_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_48_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_49_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_50_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_51_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_52_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_53_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_54_grey.jpg',
		        		 				   pathIMG+'tia/img/captcha_55_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_56_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_57_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_58_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_59_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_60_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_61_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_62_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_63_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_64_grey.jpg',
		        		 				   pathIMG+'tia/img/captcha_65_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_66_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_67_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_68_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_69_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_70_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_71_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_72_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_73_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_74_grey.jpg',
		        		 				   pathIMG+'tia/img/captcha_75_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_76_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_77_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_78_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_79_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_80_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_81_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_82_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_83_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_84_grey.jpg',
		        		 				   pathIMG+'tia/img/captcha_85_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_86_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_87_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_88_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_89_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_90_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_91_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_92_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_93_grey.jpg',
	        		 					   pathIMG+'tia/img/captcha_94_grey.jpg',
		        		 				   pathIMG+'tia/img/captcha_95_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_96_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_97_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_98_grey.jpg',
		       		 					   pathIMG+'tia/img/captcha_99_grey.jpg',
		     		 					   pathIMG+'tia/img/captcha_100_grey.jpg'
									   ),
			code	:		new Array( 'hgz6wt',
									   'retwze',
									   'fgrpe5',
									   'loijwb',
									   'kopizh',
									   'ko98j1',
									   'pi8zwh',
									   'w451jn',
									   'snash1',
					 				   'nuhz34',
					 				   'asfjuw',
					 				   '87uhbd',
					 				   'nuzrte',
					 				   'drehtr',
					 				   'lopo9d',
					 				   'kilkj3',
					 				   'lok87t',
					 				   'axmoim',
					 				   'qkoinv',
					 				   'hgz2gv',
		       		 				   'JRX10O',
		       		 				   'VQKAPW',
		       		 				   'X3QF06',
		       		 				   '9MAA01',
		       		 				   '2V9Q2V',
		       		 				   'RR1KE1',
		       		 				   'BC08LQ',
		       		 				   'YXRGOE',
		       		 				   'LOBALA',
		       		 				   '20R3SP',
		       		 				   '6D1YRZ',
		       		 				   'ZB316L',
		       		 				   'OVIUKD',
		       		 				   'NHQR53',
		       		 				   'CUB3RX',
		       		 				   '33B2BQ',
		       		 				   'RMLPL3',
		       		 				   '1VE62W',
		       		 				   '8L9ISW',
		       		 				   '2DLGFS',
		       		 				   'ENZDCA',
		       		 				   '99GOWD',
		       		 				   'N3C8MI',
		       		 				   '29JO5E',
		       		 				   'UH9LZ4',
		       		 				   'QRVDQ7',
		       		 				   'RK4MXQ',
		       		 				   'MC55X8',
		       		 				   'RBZL7W',
		       		 				   'NCV034',
		       		 				   'PP3PDJ',
		       		 				   '2ZMS99',
		       		 				   'LTXF7P',
		       		 				   'APVEIA',
		       		 				   'T8HKCP',
		       		 				   'OK8VRS',
		       		 				   '9OI3W2',
		       		 				   'ZNAMAB',
		       		 				   '0HWGD9',
		       		 				   'YX6WKM',
		       		 				   'SI6O7N',
		       		 				   'Q7P5UM',
		       		 				   'ZYVDHO',
		       		 				   '8JVS03',
		       		 				   'L29S48',
		       		 				   'Q9P1M1',
		       		 				   '550EI9',
		       		 				   'LM6OF8',
		       		 				   '19U3BY',
		       		 				   'RO7R7R',
		       		 				   '98C5H8',
		       		 				   'N6KWHY',
		       		 				   '8NKFES',
		       		 				   'EDW22Y',
		       		 				   'WTHQ6L',
		       		 				   'W653RU',
		       		 				   'SSSCYF',
		       		 				   'K6APOL',
		       		 				   'W9TLWR',
		       		 				   'AXD8X5',
		       		 				   '2TX1DP',
		       		 				   'BKUH0D',
		       		 				   'OMQJI0',
		       		 				   'BWKFUT',
		       		 				   '36LJNW',
		       		 				   'BLWQ10',
		       		 				   'CD72L6',
		       		 				   'HOWQPG',
		       		 				   '28KW9M',
		       		 				   'VYUTGK',
		       		 				   'XM14A2',
		       		 				   'JLXR94',
		       		 				   'NM2RF9',
		       		 				   'QCY5J9',
		       		 				   'GQAJ16',
		       		 				   'CY50PK',
		       		 				   'P3MQFY',
		       		 				   'XIPBRT',
		       		 				   'MB3FBN',
		       		 				   '30VUT4'
									)
		      };
   }
	$('div.captcha').each( function(i) {
		refreshCaptcha( $('div.captcha').eq(i) );
	});
	$('.captcharefresh').live( 'click', function(evt) {
		evt.preventDefault();
		refreshCaptcha( $(this).parent() );
	});
	function refreshCaptcha( caller ) {
		//console.log( caller.attr('class') );
		var randNr = GetRandom(0, capAr.img.length-1 );
		caller.find('.captchaimage > img').attr('src', capAr.img[randNr]);
		caller
			.find('input[name=captchacode]')
			.remove()
			.end()
			.append('<input type="hidden" name="captchacode" value="'+capAr.code[randNr]+'" />');
	}
	function GetRandom( min, max ) {
		if( min > max ) {
			return( -1 );
	    }
	    if( min == max ) {
			return( min );
	    }
	    return( min + parseInt( Math.random() * ( max-min+1 ) ) );
	}
	function checkCaptcha( caller ) {
		if( caller.find('input[name=captchacode]').val().toLowerCase() != caller.find('input[name=captcha]').val().toLowerCase() ) {
			caller.find('.captchainput input').addClass('invalid');
         caller.find('input[name=captcha]').addClass('invalid');
			return false;
		} else {
			return true;
		}
	}
	
	/**
	 * Print
	 */
	$('a.print').fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'padding'       :   10,
		'width'         :   646,
		'height'        :   566,
		'overlayShow'	:	true,
		'overlayOpacity':   0.8,
		'overlayColor'  :   '#000',
		'centerOnScroll':   true,
		'cyclic'        :   true,
		'type'          :   'iframe',
		'scrolling'     :   'auto',
		'autoScale'     :   false,
		'onStart'       :   function() { 
								$('#fancybox-close').css({'top':'-10px', 'right':'-10px'});
								$('body').height( $(document).height() );
							},
		'onComplete'    :   function() {
								$('#fancybox-inner').css('display', 'block');
							},
		'changeFade'	:   300,
		'titleShow'     :   false 
	});
	
	/**
	 * Link styling
	 */
	if( $('#tia-inner-content .tia-content-el, #tia-inner-content .tia-teaser, .tia-teaser-inner, .tia-news-list').find('a') ) {
		$('#tia-inner-content .tia-content-el, #tia-inner-content .tia-teaser, .tia-teaser-inner, .tia-news-list')
			.not('.tia-rent > .tia-content-el')
			.not('.tia-lightbox-voted > .tia-content-el')
			.hover( function() {
				$header = ( $(this).hasClass('tia-winner-is') ) ? 'h1' : 'h2';
				if( $(this).find('a').length > 0 ) onMouseoverTeaser( $(this), $header );
			}, function() {
				$header = ( $(this).hasClass('tia-winner-is') ) ? 'h1' : 'h2';
				if( $(this).find('a').length > 0 ) onMouseoutTeaser( $(this), $header );
			});
		$('#tia-inner-content .tia-content-el, #tia-inner-content .tia-teaser, .tia-teaser-inner, .tia-news-list')
			.not('.tia-rent > .tia-content-el')
			.not('.tia-lightbox-voted > .tia-content-el')
			.click( function(evt) {
				evt.preventDefault();
				$header = ( $(this).hasClass('tia-winner-is') ) ? 'h1' : 'h2';
				if( $(this).find('a').length > 0 ) onClickTeaser( $(this), $header );
			});
	}
	if( $('#tia-motto div.tia-text').children().not('.tia-teaser-inner').find('a') ) {
		if( ! $('#tia-motto div.tia-text').find('h1 a').length > 0 )
			$('#tia-motto div.tia-text').find('h1').wrapInner('<a href="'+$('#tia-motto div.tia-visual').find('a').attr('href')+'"></a>');
		$('#tia-motto div.tia-text').children().not('.tia-teaser-inner').hover( function() {
			if( $(this).find('a').length > 0 ) onMouseoverTeaser( $(this), 'h1' );
		}, function() {
			if( $(this).find('a').length > 0 ) onMouseoutTeaser( $(this), 'h1' );
		});
		//$('#tia-motto div.tia-text').children().not('.tia-teaser-inner').click( function(evt) {
			//evt.preventDefault();
			//if( $(this).find('a').length > 0 ) onClickTeaser( $(this), 'h1' );
		//});
	}
	if( $('#tia-motto div.tia-visual').find('a') ) {
		if( ! $('#tia-motto div.tia-text').find('h1 a').length > 0 )
			$('#tia-motto').find('h1:first').wrapInner('<a href="#"></a>');
		$('#tia-motto div.tia-visual').hover( function() {
			if( $(this).find('a').length > 0 ) onMouseoverTeaser( $(this), 'h1' );
		}, function() {
			if( $(this).find('a').length > 0 ) onMouseoutTeaser( $(this), 'h1' );
		});
		//$('#tia-motto .tia-visual a, #tia-motto > .tia-text > *:not(.tia-teaser-inner)').click( function() {
		$('#tia-motto .tia-visual a').click( function() {
			if ($(this).is('a'))
				window.location.href = $(this).attr('href');
			else
				window.location.href = $(this).find('a:first').attr('href');
			return false;
		});
		$('#tia-motto .tia-teaser-inner').click( function() {
			//window.location.href = $(this).find('a:first').attr('href');
			return false;
		});
	}
	if( $('#tia-opener div.tia-visual').find('a').length > 0 ) {
		if( ! $('#tia-opener div.tia-text').find('h1 a').length > 0 )
			$('#tia-opener').find('h1:first').wrapInner('<a href="#"></a>');
		$('#tia-opener').hover( function() {
			if( $(this).find('a').length > 0 ) onMouseoverTeaser( $(this), 'h1' );
		}, function() {
			if( $(this).find('a').length > 0 ) onMouseoutTeaser( $(this), 'h1' );
		});
		$('#tia-opener').click( function(evt) {
			evt.preventDefault();
			if( $(this).find('a').length > 0 ) onClickTeaser( $(this), 'h1' );
		});
	}
	function onMouseoverTeaser( caller, hType ) {
		caller.css({'cursor':'pointer'});
		if( hType=='h1' ) caller = caller.parent();
		caller.find(hType+' a').css({'text-decoration':'underline'});
	}
	function onMouseoutTeaser( caller, hType ) {
		caller.css({'cursor':'default'});
		if( hType=='h1' ) caller = caller.parent();
		caller.find(hType+' a').css({'text-decoration':'none'});
	}
	function onClickTeaser( caller, hType ) {
		if( hType=='h1' ) caller = caller.parent();
		if( caller.find('a:first').attr('target') == '_blank' ) {
			window.open( caller.find('a:first').attr('href'), 'newwindow' );
		} else {
			window.location.href = caller.find('a:first').attr('href');
		}
	}
	
	/*
	 * Browser specific styling (CSS)
	 */
	if( $.browser.msie && parseInt($.browser.version) < 8 ) {
		if( $('*').is('form div.media') ) {
			$('form div.media').parent().css({'height':'52px', 'margin-top':'25px', 'margin-bottom':'20px'});
		}
		if( $('*').is('form div.comingas') ) {
			$('form div.comingas').css({'height':'82px', 'margin-top':'0'});
			$('form div.comingas select[name=editor]').parent().css({'margin-top':'38px', 'left':'-54px'});
		}
	}

	/* 
	 * Update 2011
	 */
	// unbind click on label, set by default in jquery.transform.js
	// @param el container class or id, e.g. '.tia-voting-form'
	if( $('.tia-voting-form').length > 0 ) unbindLabelClick('.tia-voting-form');
	function unbindLabelClick(el) {
		$(el+' label').unbind('click', false).css('cursor', 'default');
	}
	
	//checkForVotingCookie();
	function checkForVotingCookie() {
		if( $.cookie('TIAvote') ) {
			showHideVotingForm();
			return true;
		}
		return false;
	}
	
	function showHideVotingForm() {
		$('.tia-visible').css('display', 'none');
		$('.tia-hidden').css('display', 'block');
	}
	
	// scroll to
	  function filterPath(string) {
	  return string
	    .replace(/^\//,'')
	    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
	    .replace(/\/$/,'');
	  }
	  var locationPath = filterPath(location.pathname);
	  var scrollElem = scrollableElement('html', 'body');
	  activateScrollTo(900);
	  function activateScrollTo( speed ) {	
	  		 scrollElem = ( scrollElem == '' ) ? scrollableElement('html', 'body') : scrollElem;
			 $('a.scroll-down[href*=#]').each(function() {
		    var thisPath = filterPath(this.pathname) || locationPath;
		    if (  locationPath == thisPath
		    && (location.hostname == this.hostname || !this.hostname)
		    && this.hash.replace(/#/,'') ) {
			   var $target = $(this.hash), target = this.hash;
		      if (target) {
		        var targetOffset = $target.offset().top;
		        $(this).bind('click', function(event) {
		         event.preventDefault();
					$(scrollElem).animate({scrollTop: targetOffset}, speed, 'swing', function() {
						location.hash = target;
		          });
		        });
		      }
		    }
		  });
		
		  
		  
		  
	  }

	  // use the first element that is "scrollable"
	  function scrollableElement(els) {
	    for (var i = 0, argLength = arguments.length; i <argLength; i++) {
	      var el = arguments[i],
	          $scrollElement = $(el);
	      if ($scrollElement.scrollTop()> 0) {
	        return el;
	      } else {
	        $scrollElement.scrollTop(1);
	        var isScrollable = $scrollElement.scrollTop()> 0;
	        $scrollElement.scrollTop(0);
	        if (isScrollable) {
	          return el;
	        }
	      }
	    }
	    return [];
	  }
	  
	
	  
	/* 
	 * End Update 2011
	 */
	
}); // end jQuery



HTTP_GET_VARS=new Array();
strGET=document.location.search.substr(1,document.location.search.length);
if(strGET!='')
    {
    gArr=strGET.split('&');
    for(i=0;i<gArr.length;++i)
        {
        v='';vArr=gArr[i].split('=');
        if(vArr.length>1){v=vArr[1];}
        HTTP_GET_VARS[unescape(vArr[0])]=unescape(v);
        }
    }

function GET(v) {
	if(!HTTP_GET_VARS[v]){return 'undefined';}
	return HTTP_GET_VARS[v];
}


if (!this.JSON) {
    this.JSON = {}
}

(function(){
    function f(n){
        return n < 10 ? '0' + n : n
    }
    if (typeof Date.prototype.toJSON !== 'function') {
        Date.prototype.toJSON = function(key){
            return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z' : null
        };
        String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function(key){
            return this.valueOf()
        }
    }
    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = {
        '\b': '\\b',
        '\t': '\\t',
        '\n': '\\n',
        '\f': '\\f',
        '\r': '\\r',
        '"': '\\"',
        '\\': '\\\\'
    }, rep;
    function quote(string){
        escapable.lastIndex = 0;
        return escapable.test(string) ? '"' +
        string.replace(escapable, function(a){
            var c = meta[a];
            return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4)
        }) +
        '"' : '"' + string + '"'
    }
    function str(key, holder){
        var i, k, v, length, mind = gap, partial, value = holder[key];
        if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
            value = value.toJSON(key)
        }
        if (typeof rep === 'function') {
            value = rep.call(holder, key, value)
        }
        switch (typeof value) {
            case 'string':
                return quote(value);
            case 'number':
                return isFinite(value) ? String(value) : 'null';
            case 'boolean':
            case 'null':
                return String(value);
            case 'object':
                if (!value) {
                    return 'null'
                }
                gap += indent;
                partial = [];
                if (Object.prototype.toString.apply(value) === '[object Array]') {
                    length = value.length;
                    for (i = 0; i < length; i += 1) {
                        partial[i] = str(i, value) || 'null'
                    }
                    v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
                    gap = mind;
                    return v
                }
                if (rep && typeof rep === 'object') {
                    length = rep.length;
                    for (i = 0; i < length; i += 1) {
                        k = rep[i];
                        if (typeof k === 'string') {
                            v = str(k, value);
                            if (v) {
                                partial.push(quote(k) + (gap ? ': ' : ':') + v)
                            }
                        }
                    }
                }
                else {
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = str(k, value);
                            if (v) {
                                partial.push(quote(k) + (gap ? ': ' : ':') + v)
                            }
                        }
                    }
                }
                v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
                gap = mind;
                return v
        }
    }
    if (typeof JSON.stringify !== 'function') {
        JSON.stringify = function(value, replacer, space){
            var i;
            gap = '';
            indent = '';
            if (typeof space === 'number') {
                for (i = 0; i < space; i += 1) {
                    indent += ' '
                }
            }
            else 
                if (typeof space === 'string') {
                    indent = space
                }
            rep = replacer;
            if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
                throw new Error('JSON.stringify');
            }
            return str('', {
                '': value
            })
        }
    }
    if (typeof JSON.parse !== 'function') {
        JSON.parse = function(text, reviver){
            var j;
            function walk(holder, key){
                var k, v, value = holder[key];
                if (value && typeof value === 'object') {
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = walk(value, k);
                            if (v !== undefined) {
                                value[k] = v
                            }
                            else {
                                delete value[k]
                            }
                        }
                    }
                }
                return reviver.call(holder, key, value)
            }
            text = String(text);
            cx.lastIndex = 0;
            if (cx.test(text)) {
                text = text.replace(cx, function(a){
                    return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4)
                })
            }
            if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
                j = eval('(' + text + ')');
                return typeof reviver === 'function' ? walk({
                    '': j
                }, '') : j
            }
            throw new SyntaxError('JSON.parse');
        }
    }
  
}());

/**
* hoverIntent is similar to jQuery's built-in "hover" function except that
* instead of firing the onMouseOver event immediately, hoverIntent checks
* to see if the user's mouse has slowed down (beneath the sensitivity
* threshold) before firing the onMouseOver event.
* 
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* hoverIntent is currently available for use in all personal or commercial 
* projects under both MIT and GPL licenses. This means that you can choose 
* the license that best suits your project, and use it accordingly.
* 
* // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
* $("ul li").hoverIntent( showNav , hideNav );
* 
* // advanced usage receives configuration object only
* $("ul li").hoverIntent({
*	sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
*	interval: 100,   // number = milliseconds of polling interval
*	over: showNav,  // function = onMouseOver callback (required)
*	timeout: 0,   // number = milliseconds delay before onMouseOut function call
*	out: hideNav    // function = onMouseOut callback (required)
* });
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($) {
	$.fn.hoverIntentCustomized = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;
		
		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;
			
			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// if e.type == "mouseenter"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "mouseleave"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				// if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
				ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );
			}
		};

		// bind the function to the two event listeners
		return this.bind('mouseover',handleHover).bind('mouseleave',handleHover);
	};
})(jQuery);
