// JavaScript Document
$(document).ready(function(){
	
	$('.sliderv').sliderv({transitionlength: '1000'},'none');
	
	setup_site();
	
	setup_exhibit_main();
	
	//print_email();
	
	
	
});


function setup_site(){
	
	$('#custm_fab_exp').expando({expand_height: '160px',onclick_redirect_url: '/tradeshow-rentals-las-vegas/trade-show-exhibits-las-vegas/'});
	$('#exhibit_rent_exp').expando({onclick_redirect_url: '/exhibit-rental-las-vegas/exhibit-tradeshow-rentals-las-vegas/'}); 
	$('#exhibit_design_exp').expando({onclick_redirect_url: '/trade-show-service-las-vegas/vegas-exhibit-install-and-dismantle/'});
	
	$('#submit_contact_req_exp').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: false, onclick_redirect_url: '/las-vegas-exhibit-rentals/questions-about-exhibit-rentals-in-las-vegas/'});
	
	$('#submit_design_req_exp').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: true, show_pointer: true});
	$('#submit_inquire_rental_exp').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: false, show_pointer: true});
	$('#submit_design_req_exp_rental').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: false, onclick_redirect_url: '/design_request'});
	$('#req_quote_exp').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: true, onclick_redirect_url: '/las-vegas-exhibit-rentals/questions-about-exhibit-rentals-in-las-vegas/'});
	$('#submit_apply_req_exp').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: true, onclick_redirect_url: 'https://ciims.cindexinc.com/job/de5d26'});
	$('#submit_audio_visual_req_exp').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: true, show_pointer: true});
	$('#submit_install_dismantle_req_exp').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: true, show_pointer: true});
	$('#submit_museum_exhibit_req_exp').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: true, show_pointer: true});
	
	
	$("ul.four_col_display").children('li:nth-child(4n+1)').css("marginLeft", "0px");
	$("ul.three_col_display").children('li:nth-child(3n+1)').css("marginLeft", "0px");
	$("ul.two_col_display").children('li:nth-child(2n+1)').css("marginLeft", "0px");
	
	$('a[rel=fancy_box]').fancybox();
}

function setup_exhibit_main(){
	$('.exhibit_rental_container ul.three_col_display a').click(function(){
		
		new_url = $(this).attr('href');
		//console.log('load');
		//console.log(new_url);
		$('.exhibit_main').fadeOut(400, function(){
			$(this).detach();	
		});
		$.get(new_url,{ ajax: "true"}, function(data) {
		  new_content = $('<div />').append(data);
		  //console.log(new_content.find('.exhibit_type').html());
		  //console.log(new_content.find('.exhibit_type').find('ul.two_col_display').html());
		  $('#sub_nav_container').after(new_content.find('.exhibit_type'));
		  $('.exhibit_type').hide();
		  $('.exhibit_type').fadeIn(800);
		  //$('.exhibit_rental_container').append(new_content.find('ul.two_col_display'));
		  //$('.exhibit_rental_container ul.two_col_display').fadeIn(400);
		  //$('#bread_crumb_box').fadeIn(400);
		  //$('#container').attr('class','exhibit_type');
		  //alert('Load was performed.');
		  setup_exhibit_type();
		  $("ul.three_col_display").children('li:nth-child(3n+1)').css("marginLeft", "0px");
		  $("ul.four_col_display").children('li:nth-child(4n+1)').css("marginLeft", "0px");
		});
		
		
		return false;	
	});
}

function setup_exhibit_type(){
	$('.exhibit_type ul.four_col_display a').click(function(){
		
		new_url = $(this).attr('href');
		//console.log('load');
		//console.log(new_url);
		$('.exhibit_type').fadeOut(800, function(){
			$(this).detach();	
		});
		$.get(new_url,{ ajax: "true"}, function(data) {
		  new_content = $('<div />').append(data);
		  //console.log(new_content.find('.exhibit_page').html());
		  $('#sub_nav_container').after(new_content.find('.exhibit_page'));
		  $('.exhibit_page').hide();
		  $('.exhibit_page').fadeIn(800);
		  //alert('Load was performed.');
		  setup_exhibit_page();
		  $("ul.four_col_display").children('li:nth-child(4n+1)').css("marginLeft", "0px");
		  $("ul#exhibit_thumbs").children('li:nth-child(3n+1)').css("marginLeft", "0px");
		  
		});
		
		return false;	
	});
	
	$('#bread_crumb_box').children('a').click(function(){
		
		new_url = $(this).attr('href');
		//console.log('load');
		//console.log(new_url);
		$('.exhibit_page').fadeOut(400, function(){
			$(this).detach();	
		});
		$.get(new_url,{ ajax: "true"}, function(data) {
		  new_content = $('<div />').append(data);
		  //console.log(new_content.find('.exhibit_type').html());
		  //console.log(new_content.find('.exhibit_type').find('ul.two_col_display').html());
		  $('#sub_nav_container').after(new_content.find('.exhibit_main'));
		  $('.exhibit_main').hide();
		  //$('.exhibit_rental_container').append(new_content.find('.exhibit_main'));
		  $('.exhibit_main').fadeIn(400);
		  //alert('Load was performed.');
		  setup_exhibit_main();
		  setup_site();
		});
		
		return false;	
	});
	
	$('.bc-1 a').click(function(){
		
		new_url = $(this).attr('href');
		//console.log('load');
		//console.log(new_url);
		$('.exhibit_type').fadeOut(400, function(){
			$(this).detach();	
		});
		$('.exhibit_page').fadeOut(400, function(){
			$(this).detach();	
		});
		$.get(new_url,{ ajax: "true"}, function(data) {
		  new_content = $('<div />').append(data);
		  
		  //alert(new_content.html());
		  //console.log(new_content.find('.exhibit_type').html());
		  //console.log(new_content.find('.exhibit_type').find('ul.two_col_display').html());
		  $('#sub_nav_container').after(new_content.find('.exhibit_main'));
		  $('.exhibit_main').hide();
		  //$('.exhibit_rental_container').append(new_content.find('.exhibit_main'));
		  $('.exhibit_main').fadeIn(400, function(){
		  //alert('Load was performed.');
		  setup_exhibit_main();
		  setup_site();
		  setup_form();
		  });
		});
		
		return false;	
	});
}

function setup_exhibit_page(){
	$('#submit_inquire_rental_exp').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: false, show_pointer: true});
	//$('#submit_design_req_exp').expando({inital_opacity: 1, end_opacity: 1, expand_height: '50px', float: false, show_pointer: true});
	
	$('.bc-1 a').click(function(){
		
		new_url = $(this).attr('href');
		//console.log('load');
		//console.log(new_url);
		$('.exhibit_type').fadeOut(400, function(){
			$(this).detach();	
		});
		$('.exhibit_page').fadeOut(400, function(){
			$(this).detach();	
		});
		$.get(new_url,{ ajax: "true"}, function(data) {
		  new_content = $('<div />').append(data);
		  //console.log(new_content.find('.exhibit_type').html());
		  //console.log(new_content.find('.exhibit_type').find('ul.two_col_display').html());
		  $('#sub_nav_container').after(new_content.find('.exhibit_main'));
		  $('.exhibit_main').hide();
		  //$('.exhibit_rental_container').append(new_content.find('.exhibit_main'));
		  $('.exhibit_main').fadeIn(400, function(){
		  //alert('Load was performed.');
		  setup_exhibit_main();
		  setup_site();
		  setup_form();
		  });
		});
		
		return false;	
	});
	
	$('.bc-2 a').click(function(){
		
		new_url = $(this).attr('href');
		//console.log('load');
		//console.log(new_url);
		$('.exhibit_page').fadeOut(400, function(){
			$(this).detach();	
		});
		$.get(new_url,{ ajax: "true"}, function(data) {
		  new_content = $('<div />').append(data);
		  //console.log(new_content.find('.exhibit_type').html());
		  //console.log(new_content.find('.exhibit_type').find('ul.two_col_display').html());
		  $('#sub_nav_container').after(new_content.find('.exhibit_type'));
		  $('.exhibit_type').hide();
		  //$('.exhibit_rental_container').append(new_content.find('.exhibit_type'));
		  $('.exhibit_type').fadeIn(400);
		  //alert('Load was performed.');
		  setup_exhibit_type();
		  setup_site();
		});
		
		return false;	
	});
	
	$('.bc-3 a').click(function(){
		return false;
	});
	
	setup_exhibit_images();
	setup_form();
	
	
	
}

function setup_exhibit_images(){
	$('#exhibit_thumbs li img').mouseenter(function(){
		//exhibit_img_url = $(this).attr('src');
		//bigger_img_url = exhibit_img_url.replace("318", "660");
		//full_img_url = exhibit_img_url.replace("\/318", "");
		
		//alert($(this).parent().attr('id'));
		
		
		
		_id = $(this).parent().attr('id');
		_id = _id.replace("thumb_", "");
		
		if($('#primary_img a#img_' + _id).css('display') == 'none'){
			$('a[rel=exhibit_group]').stop(true,true);
			
			$('a[rel=exhibit_group]').fadeOut(300,function(){
				//console.log('faded out');
				
			});
			$('#primary_img a#img_' + _id).delay(300).fadeIn(300);
		
		}
		//$('#primary_img').children('img').detach();
	});
	
	$('#exhibit_thumbs li').each(function(index){
		
		$(this).attr('id','thumb_' + index);
		
		new_obj = $('<a id="img_'+index+'" rel="exhibit_group" />');
		temp_url = $(this).find('img').attr('src');
		temp_main_url = temp_url.replace("318", "660");
		temp_big_url = temp_url.replace("\/318", "");
		//console.log(temp_url);
		new_obj.attr('href',temp_big_url);
		new_obj.append('<img src="'+temp_main_url+'" />');
		$('#primary_img').append(new_obj);
	});
	
	$('#primary_img a[rel=exhibit_group]').fancybox();
	
	$('a[rel=exhibit_group]').hide();
	
	$('a[rel=exhibit_group] img').load(function () {
		//$(this).hide();
		//$('#primary_img').removeClass('loading');
		if($(this).parent().attr('id') == 'img_0'){
			$(this).parent().fadeIn(600);
		}
	})
}

function print_email(){
	var temphtml = '';
	
	$('#general-form div').each(function (){
		
		if($(this).find("input").length > 0){
			temphtml += '<p style="margin:0px; padding:4px 0px; color:#595B5C; font-family:Arial, Helvetica, sans-serif; font-size:12px;"><strong>'+$(this).find('label').html()+': </strong>&lt;?= $'+$(this).find('input').attr('name')+' ?&gt;</p>\n';
		} else if ($(this).find("select").length > 0) {
			temphtml += '<p style="margin:0px; padding:4px 0px; color:#595B5C; font-family:Arial, Helvetica, sans-serif; font-size:12px;"><strong>'+$(this).find('label').html()+': </strong>&lt;?= $'+$(this).find('select').attr('name')+' ?&gt;</p>\n';
		} else if($(this).find("textarea").length > 0) {
			temphtml += '<p style="margin:0px; padding:4px 0px; color:#595B5C; font-family:Arial, Helvetica, sans-serif; font-size:12px;"><strong>'+$(this).find('label').html()+': </strong></p><blockquote style="margin:0px; padding:10px 0px; border:dashed 1px #595B5C; color:#595B5C; font-family:Arial, Helvetica, sans-serif; font-size:12px;">&lt;?= nl2br(htmlentities($'+$(this).find('textarea').attr('name')+')) ?&gt;</blockquote>\n';
		}
	});	
	
	//console.log(temphtml);
}
