$(document).ready(function(){
	var _ie6 = ($.browser.msie && $.browser.version=="6.0") ? true : false;
	if(_ie6) {		
		$('body').addClass('ie6').html('<h1 class="logo"><a href="#">LOGO</a></h1>');
		var $buoop = {} 
		$buoop.ol = window.onload; 
		window.onload=function(){ 
		 if ($buoop.ol) $buoop.ol(); 
		 var e = document.createElement("script"); 
		 e.setAttribute("type", "text/javascript"); 
		 e.setAttribute("src", "http://browser-update.org/update.js"); 
		 document.body.appendChild(e); 
		} 
	}
	$("a.external,#list-partners .item a").attr('target','_blank');
	initfocus();
	initCufon();
	//initBtnVideo();
	initBoxesHover();
	initNewsSlider();
	initClick();
	initTableProd();
	initpopup();
	initTabs();
	initHover();
	Clickbutton();
	scrolltop();
	initinformation();
	showForm();
	showBlocks()
});
$(window).load(function(){
	initHeight($('.boxes>li:not(#block-bottom .boxes > li)'));
});
function initCufon(){
	Cufon.replace('header .form label,#main header h2,ul.tabs-header strong,a.back,a.button', {fontFamily: 'Futura LT' , hover:'true' , textShadow: '2px 2px #DDDFDE' });
	Cufon.replace('#latest-slider strong', {fontFamily: 'Futura LTB' , hover:'true'});
	Cufon.replace('span.slogan,header .tel,div.control a.close,#latest-slider ul li,.box-item span.name', {fontFamily: 'Futura LT' , hover:'true'});
	Cufon.replace('#main-navigation a,header h3,#main .title h3,#main .box h4,a.konw, a.download_data', {fontFamily: 'Futura LT' , hover:'true' , textShadow: '1px 2px #DDDFDE' });
	Cufon.replace('.more-info h3,#sidebar nav ul li a, article h4:not(.posts-list article h4)', {fontFamily: 'Futura LT' , hover:'true' , textShadow: '1px 1px #DDDFDE' });
};
function initfocus(){
	$("input.form-text, .download-form input.text").each(function(){
		var _val = $(this).val();
		$(this).focus(function(){
	 	$(this).addClass('focus')
			if($(this).val()==_val){
				 $(this).val('')
			}
		});
		$(this).blur(function(){
		$(this).removeClass('focus')
			if($(this).val()==''){
				 $(this).val(_val);
			}
		});
	});
};
function initHeight(boxes){
	boxes.each(function(){
		setHeight($(this).find('div.box .holder'));
	});	
};
function setHeight(col) {  
	var maxHeight = 0;
	col = $(col);
	col.each(function() {  
	if ($(this).height()==0) {$(this).css('height','auto');}
	   if ($(this).height() > maxHeight) {	
		  maxHeight = $(this).height();
		}
	});
	col.height(maxHeight);
};
function initBoxes(){
	$('.box-f').hover(
		function () {
			$(this).addClass('hover');
		},
		function () {
			$(this).removeClass('hover');
		}
	)
};
function initBoxesHover(){
	$("#main-box .boxes").css('visibility', 'visible');
	$("#main-box .boxes .box").css('opacity', 0);
	$("#main-box .boxes .box").hover(
		function(){
			$(this).stop().fadeTo(300,1);	
		},
		function(){
			$(this).stop().fadeTo(300,0);
		})		
};
function initTableProd(){
	$("#product-table table").attr('cellpadding',0);
	$("#product-table table").attr('cellspacing',0);
	$("#product-table td, #product-table th").hover(
		function(){
			var index_v = $(this).index();
		  $(this).each(function () {
			
			$("#product-table table tr td, #product-table table tr th").each(function(){
				if(index_v == $(this).index()){
					$(this).addClass('light');
					if($(this).find('span:first').length){
						$(this).parent().find('td.title-prod').addClass('title-light');
					}
				}
				
			});
		});
		},
		function(){
			$("#product-table table tr td, #product-table table tr th").removeClass('light').removeClass('title-light');	
		}
	);
 
};
function initBtnVideo(){
	setTimeout(function() {
		$('#main-box .video-btn').css('z-index', 100).fadeIn(800, function(){
		})
	}, 5000);
	$('#main-box .video-btn').click(function (){
		$('#main-box div.graphic').css('visibility', 'hidden');
		$('#main-box #video .frame').css('z-index', 100).fadeIn(800,function(){
		});
		$('#main-box .video-btn').fadeOut(800,function(){
			$('#main-box .video-btn').css({'z-index': 0});		
		});
		$('#main-box .boxes').fadeOut(800,function(){
			$('#main-box .boxes').css({'z-index': 0});
		})
	});
	$('#video a.close').click(function (){
		var _ie7 = (($.browser.msie && $.browser.version=="7.0") || ($.browser.msie && $.browser.version=="8.0")) ? true : false;
		if(!(_ie7)) {
			var v = $("#example_video")[0];
			v.pause();
		}
		$('#main-box .boxes').css('z-index', 100).fadeIn(500,function(){
			setTimeout(function() { 
			$('#main-box .video-btn').css('z-index', 100).fadeIn(500, function(){
			})
		}, 5000);
		});
		$('#main-box div.graphic').css('visibility', 'visible');
		$('#main-box #video .frame').fadeOut(500,function(){
			$('#main-box .boxes').css({'z-index': 0});
		});		
	});	
};
function initNewsSlider(){
	if ($('#latest-slider ul').length == 0){
		return false;
	}
	$('#latest-slider ul').cycle({ 
		fx:     'scrollUp', 
		timeout: 6000 
	});
};
function initClick(){
	$('#boxes-hide li .box a.hidden').click(
		function(){
			$('#boxes-hide li .box').removeClass('selected selected-load');
			var th = $(this);
			$(this).parents('.box').addClass('selected'); 
			var loadblock =$(this).attr('href');
			External(loadblock);			
		return false;
		}
	
	);
	
};
function External(load_block){
	/*if (load_block[0] != "/" && $('#block-bottom ul.boxes li.'+load_block).length) {
		$('.load-block').show().css('visibility', 'hidden');
		var _current = $('.' + load_block);
		var _height = _current.height();
		$('.load-block').hide();
		$('#block-bottom').animate({
			'height': _height
		}, 500, function(){
			_current.css('visibility', 'visible').fadeTo(300, 1,function(){
				initHeight(_current);
			});
			$('#boxes-hide li .selected').removeClass('selected').addClass('selected-load');
			$('html,body').scrollTo($('body').height());
		});
	}
	else {		*/
		//	url: "external-html/" + load_block + ".html",
		$('#block-bottom').animate({
					'height': "0px"
				}, 500);
		$.ajax({
			type: "GET",
			url: load_block,
			dataType: "html",
			success: function(msg){
				$('#block-bottom ul.boxes').html(msg);
				$('#block-bottom ul li:last').addClass(load_block);
				initCufon();
				var loadblock = $(this).attr('href');
				$('.load-block').show().css('visibility', 'hidden');
				var _current = $('.load-block');
				var _height = _current.height();
				$('.load-block').hide();
				$('#block-bottom').animate({
					'height': "284px"
				}, 500, function(){
					_current.css('visibility', 'visible').fadeTo(300, 1,function(){
						initHeight(_current);
					});
					$('#boxes-hide li .selected').removeClass('selected').addClass('selected-load');
					$('html,body').scrollTo($('body').height());
				});
				
			}
		});
		
	//}
};
function initpopup(){
	$(".box-item a.popup").click(function(){
		var popup_selector = '#' + $(this).attr('rel');
		initCufon();
		$(popup_selector).jpopup({
			close: true,
			shadow: false,
			opacity: 0.8,
			background: '#000'
			//,onShow: reInit
			//,onHide: reInit
		});
		return false;
	});
};
function initTabs(){
	if ( $('div.tabs').length == 0 ) return false;
	
	$('div.tabs > ul.tabs-header > li > a').click(function(){
		var href = $(this).attr('href');
		href = href.replace(/[^#]*#/,'');
		$('div.tabs > ul.tabs-header > li > a').removeClass('active');
		$('div.tabs > div.tabs-content').removeClass('active-tabs-content');
		$('#'+href).addClass('active-tabs-content');
		$(this).addClass('active');
		
		return false;
	});
}
function initHover(){
	$('area').hover(
		function(){ 
		var button = '.' + $(this).attr('alt');	
		$(button).show();		
		},
		function(){ 
		var button = '.' + $(this).attr('alt');	
		setTimeout(function() {
		$(button).hide();
	}, 4000);
		}	
	);
}
function Clickbutton(){
	$('a.button').click(
		function(){
			var url = $(this).attr('href');
			$.ajax({
			type: "GET",
			url : url,
			dataType: "html",
			success: function(msg){
				$('.content-partners').html(msg);
				$('.breadcrumb span').remove();
				var test = $('.content-partners h2').html();
				$('.breadcrumb').append('<a href="">sales partners</a> <span>'+ test +'</span>');
				$("a.external").attr('target','_blank');
				initCufon();
				$('.map-block').fadeOut(300);
				$('.content-partners').fadeIn(300);
			buttonback();
			}
		});
		return false;
		
		}
	);
		
};
function buttonback(){
	$('a.back').click(
		function(){
			$('.content-partners').fadeOut(300);
			$('.map-block').fadeIn(300);
			$('.breadcrumb span').remove();
			$('.breadcrumb a:last').remove();
			$('.breadcrumb').append('<span>sales partners</span>');
			
		return false;
		}
	
	);
};
function scrolltop(){
	$('a.up').click(
		function(){ 
		$('body').scrollTo( 0, 800, {queue:true} );
		return false;
	 }
	);	
};
function initinformation(){
	$('#information-link').click(
		function(){ 
		$(this).removeClass().addClass('hide').html('Less Information');
		$('.information-content').slideDown('200');
		$(this).unbind('click');
		initinformation1();
		return false;
	  }
	);	
};
function initinformation1(){
	$('#information-link').click(
		function(){ 
		$(this).removeClass().addClass('view').html('More Information');
		$('.information-content').slideUp('200');
		$(this).unbind('click');
		initinformation();
		return false;
	 	
	 }
	);
};
function showForm(){
	$('.download-link').click(function(e){
		$(this).hide().parent().find('.download-form').slideDown(500,function(){
			$('.boxes .holder').css('height','auto');
			initHeight($('.boxes'));
		});
		e.preventDefault();
	})
};
function showBlocks(){
	$('.open-block').click(function(){
		$(this).parent().find('.boxes-content').slideToggle(800,function(){
			$('.boxes.s2 .holder').css('height','auto');
			initHeight($('.boxes'));
		});
		$(this).toggleClass('close-block');
	})
};
