
jQuery(document).ready(function(){
	
	Shadowbox.init({players: ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv']});
		
	$(".lazy").lazyload({         
    	placeholder : "gfx/white.gif",
    	effect      : "fadeIn",
    	failurelimit : 1,
    	threshold 	: 0
    	
 	});
	
	/*// Home player mouseenter and leave
	$(".home_player").mouseenter(function(){
      	
		$(".text", this).css({
			
			display:"block"
		});
		
	}).mouseleave(function(){
				
		$(".text", this).css({
			
			display:"none"
		});
	});*/
	
	// Home logos
	$(".brands_home li").mouseenter(function(){
      	
		 
		$(this).css('border', '1px solid #b80718');
	 	
	});
	
	$(".brands_home li").mouseleave(function(){
				
		$(this).css('border', '1px solid #7c7c7c');
		
	});
	
	
	// Home player mouseenter and leave
	$(".home_player").mouseenter(function(){
      	
		 
		$('.text', this).css('filter', 'alpha(opacity=70)');
	 	$(".text", this).fadeIn(500);
		 
	});
	
	$(".home_player").mouseleave(function(){
				
		$(".text", this).fadeOut(500);

	});
	
	
	
	// Mouseover on home slider
	var items = $('#wrapper #slider-nav li').mouseenter (function () {
		
		// Clear interval
		clearInterval (slider);
		
		// Remove active
		$('#wrapper #slider-nav li.active').removeClass('active');
		
		// Set active
		$(this).addClass('active');
		
		// Calculate the offset
		offset = items.index(this) + 1;
		
		if (jQuery.browser.msie && (parseInt(jQuery.browser.version) == 6 || parseInt(jQuery.browser.version) == 7)) {
  				
			switch (offset) {
			
				case 2:
					offset = 200;
					break;
				
				case 3:
					offset = 400;
					break;
				
				case 4:
					offset = 600;
					break;
			
				case 5:
					offset = 800;
					break;
					
				default: 
					offset = 0;
					break;
			}
			
		} else {
		 
			if (offset == 1) { 
				
				offset = (offset * 205) - 205;
			} else { 
				
				offset = (offset * 205) - 210;
			}
		}
		
		// Set offset
		$('#slider-items').stop().animate({marginTop: '-' + offset}, 800, 'easeInOutBack');
	});
	
	// Home interval
	var slider = setInterval (function () {
		
		// Remove active
		active = $('#wrapper #slider-nav li.active');
		
		// Calculate next
		next = items.index(active) + 1;
		
		// Check for offset
		if (next == items.length)
			next = 0;
		
		// Fetch next
		slide = $(items).get(next);
				
		// Remove active
		$(active).removeClass('active');
		$(slide).addClass('active');
		
		// Offset
		if (jQuery.browser.msie && (parseInt(jQuery.browser.version) == 6 || parseInt(jQuery.browser.version) == 7)) {
		
			offset = (next * 200);
			
		} else {
			
			offset = (next * 205);
			
		}
		
		// Set offset
		$('#slider-items').stop().animate({marginTop: '-' + offset}, 800, 'easeInOutBack');
		
	}, 5000);
	
	// Dialogs
 	$("a#dialog").fancybox({
 		
 		'frameWidth': 300,
 		'frameHeight': 80,
 		'overlayShow': false
 	});
	
 	// Trigger dialog
	$("a#dialog").trigger('click');
	
	// Filter popup
	$('.filter span').click (function () {
		
		// Remove all chosen stuff if not submitted.
		$("#search_form").each (function (){ this.reset(); });
		
		// Toggle multiselect in this filter
		var option = $('.options', $(this).parent()).toggle();
		
		// Hide all other options
		$('.options').not($(option)[0]).hide();
		
		// Fetch position and lengths
		var position = $(this).parent().position();
		var width = parseInt($(option).css('width')) + parseInt($(option).css('paddingLeft')) + parseInt($(option).css('paddingRight'));
		
		// Check if position
		if ((length = position.left + width) > 800) {
			
			// Set margin left
			$(option).css('marginLeft', '-' + ((length + 1) - 800) + 'px');
		}
	});
	
	// Register close filter button
	$('.filter input.button').click (function () { $('.options').hide(); });
	
	// Tabs on detail page
	$('ul.tabs li a').click (function () {
		
		// Elem
		var elem = $(this).parent();
		
		// Remove active
		$('ul.tabs li').removeClass('active');
		$(elem).addClass('active');
		
		// Fetch content
		$('div.section').hide();
		$('.detail div.section.' + $(this).attr('class')).show();
	});
	
	// Tabs on detail page
	$('a.tech').click (function () {
		
		// Elem
		var elem = $('ul.tabs li a.technology');
		
		// Remove active
		$('ul.tabs li').removeClass('active');
		$(elem.parent()).addClass('active');
		
		// Fetch content
		$('div.section').hide();
		$('.detail div.section.' + elem.attr('class')).show();
	});
	
	// Home tabs	
	
	$("ul#seo_tab li").click(function (){
		
		var he = $("#item_" + $(this).attr("id")).height() + 50 + 1180 + 342 + 372;
		
		$("ul#seo_tab li").removeClass("selected");
		$(this).addClass('selected');
		
		$(".seo_tabcontent").css("display", "none");
		$("#item_" + $(this).attr("id")).css("display", "block");
		
		$("#main").css("height", he + "px");
		
	});
		
});

// Set new image
function displayImage (imgsrc) {
		
	// Set new image to display
	$(".large .view").css("background", "url(\'" + imgsrc + "\') no-repeat center");
}
