
this.screenshotPreview = function(){

	xOffset = 90;
	yOffset = 22;

	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<div id='screenshot'><img src='"+ this.rel +"' alt='Screenshot' /><label>"+ this.t +"</label></div>");
		$("#screenshot").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("medium");
    },
	function(){
		this.title = this.t;
		$("#screenshot").remove();
    });
	$("a.screenshot").mousemove(function(e){
		$("#screenshot").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px");
	});
};



$(document).ready( function(){




	if ($('#rotation ul')) {
		$('#rotation ul').innerfade({
			animationtype: 'slide',
			speed: 750,
			timeout: 6000,
			type: 'sequence',
			containerheight: '708px'
		});
	}

	if ($('#HomepageRotation ul')) {
		$('#HomepageRotation ul').innerfade({
			animationtype: 'slide',
			speed: 750,
			timeout: 6000,
			type: 'sequence',
			containerheight: '373px'
		});
	}

	//button rollovers.
	if ($('div#Navigation')) {
		$('div#Navigation ul li a').append('<span class="hover"></span>').each(function () {
			var $span = $('> span.hover', this).css('opacity', 0);
			$(this).hover(function () {
				$span.fadeTo(300, 1);
			}, function () {
				$span.fadeTo(300, 0);
			});
		});
	}


	if ($('div.gallery-page')) {
		current_page = 1;
		total_pages = $('div.gallery-page').length;

		$("a#gallery-next").css({'visibility': 'visible'});
		$("a#gallery-prev").css({'visibility': 'visible'});
		$("div#gallery-paging-desc p").html('PAGE '+ current_page +' OF '+ total_pages);
		$("a#gallery-next").click(function () {
			current_page++;
			if (current_page > total_pages) current_page = total_pages;
			$("div#gallery-paging-desc p").html('PAGE '+ current_page +' OF '+ total_pages);
			if (current_page <= total_pages) {
				new_pos = (current_page - 1) * 900;
				$("#gallery-thumbs").animate({marginLeft: '-'+new_pos+'px'}, { duration: 700, easing: 'easeInOutQuart'});
			} else {
				current_page = total_pages;
			}
			return false;
		});
		$("a#gallery-prev").click(function () {
			current_page--;
			if (current_page < 1) current_page = 1;
			$("div#gallery-paging-desc p").html('PAGE '+ current_page +' OF '+ total_pages);
			if (current_page >= 1) {
				new_pos = (current_page - 1) * 900;
				$("#gallery-thumbs").animate({marginLeft: '-'+new_pos+'px'}, { duration: 700, easing: 'easeInOutQuart'});
			} else {
				current_page=1;
			}
			return false;
		});

		screenshotPreview();
		$('div.gallery-page img').hover(function() {
			$(this).stop().fadeTo("medium", 0.5);
		}, function() {
			$(this).stop().fadeTo("medium", 1);
		});

		$('div#HomepageModels img').hover(function() {
			$(this).stop().fadeTo("medium", 0.5);
		}, function() {
			$(this).stop().fadeTo("medium", 1);
		});

	}

	if ($('div#searchform-submit')) {
		$('div#searchform-submit a').click(function(e) {
			e.preventDefault();
			$('form#MyModelSearchForm_ModelSearchForm').submit();
		});
	}




	if ($('div#ModelSearchPreview')) {

		//this adds the models id into the checkbox ID attribute.
		$('div.ModelSearchSection').each(function() {
			var id = $(this).attr('id');
			id = id.replace('ModelSearchSection', '');

			$(this).find('input').each(function() {
				var new_id = $(this).attr('id');
				new_id = new_id.replace('ModelSearchCheckbox', 'ModelSearchCheckbox'+id+'_');
				$(this).attr('id', new_id).attr('name', new_id);
			})
		})

		$('div.ModelSearchImage').click(function(e) {
			if ($(this).find('input').is(':checked')) {
				$(this).removeClass('ModelSearchImageSelected').addClass('ModelSearchImage');
				$(this).find('input').attr('checked', '');
			} else {
				$(this).removeClass('ModelSearchImage').addClass('ModelSearchImageSelected');
				$(this).find('input').attr('checked', 'checked');
			}
		})

		$('div.ModelSearchImage input').click(function(e) {
			e.stopPropagation();
			if ($(this).is(':checked')) {
				$(this).parent().parent().removeClass('ModelSearchImage').addClass('ModelSearchImageSelected');
			} else {
				$(this).parent().parent().removeClass('ModelSearchImageSelected').addClass('ModelSearchImage');
			}

		});
	}

	$('div#emailmodelprofilesform-submit1 a').click(function(e) {

		e.preventDefault();

		if ($('div#SearchFormContainer') && $('input#sendemail').val() == '0') {

			var err = false;
			if (jQuery.trim($('input#MyEmailModelProfilesSearchForm_EmailModelProfilesSearchForm_ModelNumbers').val()) == '') {
				window.alert('please enter some model numbers.');
				err = true;
			}
			if (jQuery.trim($('input#MyEmailModelProfilesSearchForm_EmailModelProfilesSearchForm_Recipient1').val()) == '' && err == false) {
				window.alert('please enter some recipients');
				err = true;
			}
			if (!err) {
				$('form#MyEmailModelProfilesSearchForm_EmailModelProfilesSearchForm').submit();
			}
		} else {
			if ($('input#sendemail').val() == '1') {
				$('form#MyEmailModelProfilesSearchForm_EmailModelProfilesSearchForm').submit();
			}
		}
	})

	if ($('div#SearchFormContainer') && $('input#sendemail').val() == '0') {
		$('div#SearchFormContainer').css('display', 'block');



	} else {
		$('textarea#MyEmailModelProfilesSearchForm_EmailModelProfilesSearchForm_Recipients').val($('input#MyRecipients').val());
		$('textarea#MyEmailModelProfilesSearchForm_EmailModelProfilesSearchForm_Message').val($('input#MyMessage').val());
	}

	$('a.lb').lightBox({
		imageLoading:			'themes/frm/images/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
		imageBtnPrev:			'themes/frm/images/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
		imageBtnNext:			'themes/frm/images/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
		imageBtnClose:			'themes/frm/images/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
		imageBlank:				'themes/frm/images/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)

	});

	$('a.lb img').hover(function() {
		$(this).stop().fadeTo("medium", 0.5);
	}, function() {
		$(this).stop().fadeTo("medium", 1);
	});

	$('div.PressArchivePageContainer').each(function () {
		max_height = 0;
		$(this).find('span.Title').each(function() {
			if (parseInt($(this).height()) > max_height) max_height = parseInt($(this).height());
		});
		if (max_height > 0) {
			$(this).find('span.Title').height(max_height);
		}
	});



});

