function openSpecialBanner(){
	$('#keep_on_eye-banner-content').width($('#keep_on_eye-banner-content').parents('.max').width()).height(295).css('z-index', '200').parents('.keep_on_eye-box').css('z-index', '200');
}
function closeSpecialBanner(){
	$('#keep_on_eye-banner-content').width(($('#keep_on_eye-banner-content').parents('.max').width()/2) + 10).height(234).css('z-index', '').parents('.keep_on_eye-box').css('z-index', '');
}
/* jQuery */ jQuery(document).ready(function($){
	$('a[rel^=external], area[rel^=external], form[class^=external]').attr('target','_blank');

	/* files Rewrite Route */
	$("a[href*='/files/'], img[src*='/files/']").each(function(){
		if(this.tagName == 'A'){
				if(this.href.indexOf('upload') == -1){ this.href = this.href.replace('/files/', '/upload/files/'); }
		} else {
			// if (this.parent.className != "gallery-item")
				if(this.src.indexOf('upload') == -1){ this.src = this.src.replace('/files/', '/upload/files/'); }
		}
	});
	
	/* image_resources Rewrite Route */
	$("a[href*='/image_resources/'], img[src*='/image_resources/']").each(function(){
		if(this.tagName == 'A'){
			if(this.href.indexOf('upload') == -1){ this.href = this.href.replace('/image_resources/', '/upload/image_resources/'); }
		} else {
			if(this.src.indexOf('upload') == -1){ this.src = this.src.replace('/image_resources/', '/upload/image_resources/'); }
		}
	});

	/* Transform Form`s */
	$('.jquery-transform').transform({ compare : false });

	/* IE6 click png Fix */
	if($.browser.msie && $.browser.version < 7) {
		$(':regex(class,^button-)').css('cursor','pointer').click(function(){
			$(this).parents().filter('form').submit();
		});
		$('div#header div#search-box div.search-mask').click(function(){
			$('input',$(this)).focus().select();
		});
	}

	/* IE6 min-width Fix */
	$(window).bind('resize.minwidthfix', function() {
		if($.browser.msie && $.browser.version < 7) {
			$('.max, .block').parent().width((($(window).width() <= parseFloat($('#wrap').css('min-width'))) ? parseFloat($('#wrap').css('min-width')) : '100%'));
		}
	});

	/* Flaps Control */
	$('.flaps a').click(function(){
		if($(this).parent().hasClass('ignore')) { return; }
		if($(this).hasClass($(this).attr('class').split(" ")[0] + '_active')) { return false; }
		$('a', $(this).parent().parent()).each(function(i){
			$(this).removeClass($(this).attr('class').split(" ")[0] + '_active');
		});
		$($(this).parent().parent().parent().next('.fragments')).children('div').hide();
		$($(this).addClass($(this).attr('class').split(" ")[0] + '_active').attr('href')).fadeIn('slow');
		$('.jcarousel_' + $(this).attr('href').replace('#fragment-','')).jcarousel();
		return false;
	});
	$('.flaps-vertical a').click(function(){
		if($(this).parent().hasClass('ignore')) { return; }
		if($(this).hasClass('bold')) { return false; }
		$('.flaps-vertical a').removeClass('bold');
		$('.fragments-vertical').children('div').hide();
		$($(this).addClass('bold').attr('href')).fadeIn('slow');
		return false;
	});

	/* Prevent Img Width Overflow */
	$('.news-frame .news-items .news-item .news-details .news-description img').each(function(i, img){
		if($(img).width() > $('.news-frame').width()){
			$(img).attr({ 'width': $('.news-frame').width() }).removeAttr('height').wrap('<a href="'+$(img).attr('src')+'" class="expand"></a>');
		}
	});

	/* Gallery Carousel */
	$('.jcarousel').jcarousel();
		
    $('.jcarousel-big-event').jcarousel({
        auto: 10,
        wrap: 'circular',
        initCallback: event_initCallback,
		buttonNextHTML: null,
		buttonPrevHTML: null
    });

	function event_initCallback(carousel)
	{
	    // Disable autoscrolling if the user clicks the prev or next button.
	    carousel.buttonNext.bind('click', function() {
	        carousel.startAuto(0);
	    });

	    carousel.buttonPrev.bind('click', function() {
	        carousel.startAuto(0);
	    });

	    // Pause autoscrolling if the user moves with the cursor over the clip.
	    carousel.clip.hover(function() {
	        carousel.stopAuto();
	    }, function() {
	        carousel.startAuto();
	    });
	}
    /**
	 * We use the initCallback callback
	 * to assign functionality to the controls
	 */
	function mycarousel11_initCallback(carousel) {
	    $('#next-event-carousel').bind('click', function() {
	        carousel.next();
	        return false;
	    });

	    $('#prev-event-carousel').bind('click', function() {
	        carousel.prev();
	        return false;
	    });
	};

	// Ride the carousel...
    $(".events_carousel").jcarousel({
        scroll: 1,
        initCallback: mycarousel11_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });

	
	
	
	/* Gallery Lightbox */
	$("a[rel=gallery]").fancybox({ 'titlePosition' : 'inside' });
	$("a[rel=gallery_001]").fancybox({ 'titlePosition' : 'inside' });
	$("a[rel=gallery_002]").fancybox({ 'titlePosition' : 'inside' });
	$("a[rel=gallery_003]").fancybox({ 'titlePosition' : 'inside' });
	$("a[rel=gallery_004]").fancybox({ 'titlePosition' : 'inside' });
	$("a[rel=gallery_005]").fancybox({ 'titlePosition' : 'inside' });

	/* Expand Picture Lightbox */
	$("a.expand").fancybox({ 'titleShow' : false });
	$("a.expand_with_title").fancybox({ 'titlePosition' : 'inside' });

	/* Open Iframe Modal */
	$("a.modal").fancybox({ 'titleShow' : false });

	/* Movie Control */
	// $("a[rel=movie]").click(function(){
	// 		$('#movie').html('<OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="640" height="486"codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="/media/special_projects/graphics_resources/' + $(this).attr('href').replace('#','') + '"><param name="autoplay" value="true"><param name="controller" value="true"><param name="loop" value="true"><param name="scale" value="tofit"><EMBED src="/media/special_projects/graphics_resources/' + $(this).attr('href').replace('#','') + '" width="640" height="486" autoplay="true" controller="true" loop="true" scale="tofit" pluginspage="http://www.apple.com/quicktime/download/"></EMBED></OBJECT>');
	// 		return false;
	// 	});

	/* Accordion */
	$('.accordion').accordion({ autoHeight: false, clearStyle: true });
	
	/* Enable Scroll */
	$('html').css('overflow-y','scroll');
	
	/* sales_team_magic */
	$('a.sales_team_magic').click(function(){
		if($(this).hasClass('bold')){ return false; }
		$('.sales_team_magic').fadeIn();
		$('.sales_team_magic_elements').children('div').hide();
		$($(this).attr('href')).fadeIn('slow');
		$('a.sales_team_magic').removeClass('bold');
		$(this).addClass('bold');
		window.scrollTo(0,0)
		return false;
	});
	
	/* blockquote to title */
	$('blockquote').each(function(i){
		var title = $(this).text();
		$(this).before(
		'<div class="content-title" style="background:transparent; margin-bottom:-6px; overflow:hidden; margin-top:2px;">' +
			'<div id="content-title' + (i + 1) + '" style="height:24px; line-height:24px; display:block;">' +
				'<h2>' + title + '</h2>' +
			'</div>' +
		'</div>' +
		'<div class="hr"></div>').remove();
		var flashvars = { 'title':jQuery.trim(title), color:global_flash_color };
		var params = { 'bgcolor':'#FFFFFF', 'wmode':'transparent', 'play':'true', 'loop':'true', 'quality':'high', 'devicefont':'false', 'salign':'' };
		swfobject.embedSWF("/swf/DIN 1451 Std Engschrift.swf", "content-title" + (i + 1), "860", "24", "9.0.0", "/inc/javascripts/swfobject/expressInstall.swf", flashvars, params);
	});
	
	// Autocomplete
	$("#search_input").autocomplete('/autocomplete',{
		width: 229,
		scroll: true,
		scrollHeight: 300,
		minChars: 3,
		max: 999999,
		matchContains: true,
		matchCase: true,
		formatResult: formatResult
	});
	
	function formatResult(row){
		return row[0].replace(/(<.+?>)/gi, '')
	}
	
	// Brands and Platforms
	$(".brands_and_platforms-platforms-icons a").click(function(event){
		
		if($(this).attr("href").indexOf("#") != -1)
		{
			// remove the pin from all element
			$(".brands_and_platforms-platforms-icons a").each(function(){
				$(this).removeClass("active");
			});
			// add the pin
			$(this).addClass("active");
			
			event.preventDefault();

			$(".brands_and_platforms-platform-description").each(function(){
				$(this).hide();
			});
			
			$("#platform-" + $(this).attr("href").replace("#","")).fadeIn();

			$(".brands-brands").each(function(){
				$(this).hide();
			});

			$("#brands-" + $(this).attr("href").replace("#","")).fadeIn();
			
			$("#all-brands").fadeIn("slow");
			
		}
		
	});
	
	$("#all-brands").click(function(event){
		
		event.preventDefault();
		
		$(this).fadeOut("slow");
		
		$(".brands_and_platforms-platforms-icons a").each(function(){
			$(this).removeClass("active");
		});
		
		$(".brands_and_platforms-platform-description").each(function(){
			$(this).hide();
		});
		
		$("#platform-abril").fadeIn();
		
		$(".brands-brands").each(function(){
			$(this).hide();
		});

		$("#brands").fadeIn();
		
	});
	
	function menuRounded(){
		var leftCorner = '<img class="corners left_corner" src="/images/all/menu/left_corner.png" />';
		var rightCorner = '<img class="corners right_corner" src="/images/all/menu/right_corner.png" />';
		
		$('.main-level').each(function(){
		 	$(this).css('position','relative').prepend(leftCorner + rightCorner);
		});
	}

	function initMenu(){
		var section;

		$('.main-level').each(function(){
			if($("a", this).hasClass("active"))
			{
				if(customization)
				{
					$(this).css("background","url('/images/pt/customization/" + customization + "/menu/active.jpg') repeat-x");
				}else{
					$(this).css("background","url('/images/all/menu/active.jpg') repeat-x");
					if ($("ul#subnav").length > 0) {
						$(this).append("<div class='pin'><img src='/images/all/menu/arrow-up.png' alt='' style='display:block;'></div>");
					};
					
				}
			}
		});

		$('.main-level').mouseenter(function(){

			if($(".pin", this)){
				// $(".pin", this).css("display","none");
			}

			if(customization)
				$(this).css("background","url('/images/pt/customization/" + customization + "/menu/active.jpg') repeat-x");
			else
				$(this).css("background","url('/images/all/menu/active.jpg') repeat-x");

			$("a", this).first().css("color","#fff");
		}).mouseleave(function(){

			if($(".pin", this) && $(".pin", this).css("display") == "none"){
				$(".pin", this).css("display","block");
			}

			if(!$("a", this).hasClass("active"))
			{
				$(this).css("background","none");
				$("a", this).first().css("color","#464646");
			}
		});

		$(".main-level > a").click(function(e){
			if(	$(this).hasClass("open-tabelas-gerais") || 
				$(this).hasClass("open-premio-abril") || 
				$(this).hasClass("open-equipe-comercial") || 
				$(this).hasClass("open-especificacoes-tecnicas") || 
				$(this).hasClass("open-classificados"))
			{
				
				e.preventDefault();

				$("#submenu .max div").each(function(){
					$(this).css("display","none");
				});

				section = "." + $(this).attr("class").replace("open-","");

				$("#submenu").fadeIn("fast");
				$("#submenu "+section).fadeIn("fast");

				$("li", section).mouseenter(function(){
					$("ul", this).css("display","block");
				}).mouseleave(function(){
					$("ul", this).css("display","none");
				});
			}
		});

		

	}

	$("#subnav > li").each(function(){
		if ($("a", this).hasClass("sites_active") || 
			$("a", this).hasClass("magazines_active") || 
			$("a", this).hasClass("mobile_active") || 
			$("a", this).hasClass("events_active") || 
			$("a", this).hasClass("award_active") || 
			$("a", this).hasClass("categories_active") || 
			$("a", this).hasClass("contact_active") || 
			$("a", this).hasClass("event_active") || 
			$("a", this).hasClass("finalists_active") || 
			$("a", this).hasClass("jurors_active") || 
			$("a", this).hasClass("winners_active") || 
			$("a", this).hasClass("out_of_home_active") || 
			$("a", this).hasClass("general_information_active") || 
			$("a", this).hasClass("payment_methods_active") || 
			$("a", this).hasClass("restrictions_active") || 
			$("a", this).hasClass("price_list_active") || 
			$("a", this).hasClass("mtv_active") || 
			$("a", this).hasClass("digital_active") || 
			$("a", this).hasClass("classifieds_active") || 
			$("a", this).hasClass("region_active") || 
			$("a", this).hasClass("ipad_active")) {
			if(customization)
				$(this).css("background","url('/images/pt/customization/"+ customization +"/menu/bullet-active.png') no-repeat 10px center")
			else
				$(this).css("background","url('/images/all/menu/bullet-active.png') no-repeat 10px center")
		}
		$(this).append("<div class='pin-3rd'><img src='/images/all/menu/arrow-up-3rd.png' alt=''></div>");
	});

	$("#subnav > li").mouseenter(function(){
		$("ul", this).css("display", "block");
		if($("ul", this).length > 0)
			$(".pin-3rd", this).css("display","block");
	}).mouseleave(function(){
		$("ul", this).css("display", "none");
		$(".pin-3rd", this).css("display","none");

	});

	menuRounded();
	initMenu();
	
	/* pageTracker-UA-5652544-1.swf */
	/* swfobject.embedSWF("/swf/pageTracker-UA-5652544-1.swf", "pageTracker-UA-5652544-1", "1", "1", "9.0.0", "/inc/javascripts/swfobject/expressInstall.swf", {}, {}); */

	$(window).resize();
/* End jQuery */ });

/* javascript */ window.onload = function(){

/* End javascript */ };
