$(document).ready(function(){
	// Set up fade effects for hover
	$('.peekInfo .modalImage a.expand').fadeTo(0,0.75);
	$('.peekInfo .modalImage a.expand').hover(
		function() {
			$(this).fadeTo('fast',1.0);
		},
		function() {
			$(this).fadeTo('fast',0.75);			
		}
	);
	
	// Loop through each slide and re-layout
	/*
	if(navigator.userAgent.indexOf("Safari") != -1)
		backImg = escape($('.peekInfo .modalImage .thumb img').attr('src'));
	else
		backImg = $('.peekInfo .modalImage .thumb img').attr('src');
	*/
	backImg = escape($('.peekInfo .modalImage .thumb img').attr('src'));

	$('.peekInfo .modalImage .thumb').css({
		'background-image': 'url(' + backImg + ')'
	}).children("img").hide();

	// Create modal popup	
    $('.peekInfo .modalImage a.expand2,.peekInfo .modalImage a.expand').click(function(){
		parEl	= $(this).parent('div');
		parEl.toggleClass('current');

		proInfo	= parEl.children('.info2');

		modClases = $(this).attr('class').split(' ');

		for(i = 0; i < modClases.length; i++) {
			if(modClases[i].indexOf('width') > -1)
				modWidth = parseInt(modClases[i].replace(/width-/, ''));
			else if (modClases[i].indexOf('height') > -1)
				modHeight = parseInt(modClases[i].replace(/height-/, ''));
				
		}

		srcFile	= $(this).attr('href');
		srcExt	= srcFile.toLowerCase().split('.').slice(-1);

		if(srcExt == 'swf') {
			container = '<div class="modalFlash"></div>';
			
			 $.modal(container + '<p>' + proInfo.html() + '</p>', {
				containerCss: {
					width: modWidth
				}
			});
			$('.modalFlash').flash(
				{
					src: srcFile,
					width: modWidth,
					height: modHeight
				},
				{ version: 9 }
			);
			$('.flash-replaced div.alt').hide();
		} else if(srcExt == 'mp3') {
			container = '<div class="modalMp3"></div>';
			
			 $.modal(container + '<p>' + proInfo.html() + '</p>', {
				containerCss: {
					width: 400
				}
			});
			$('.modalMp3').flash(
				{
					src: '/themes/oomph/flash/player_mp3_maxi.swf',
					width: 400,
					height: 20,
					flashvars: { 
						mp3 : srcFile,
						width : 400,
						showstop : 1,
						showinfo : 1,
						showvolume : 1,
						bgcolor1 : 'ffffff',
						bgcolor2 : 'cccccc',
						buttoncolor : '999999',
						buttonovercolor : 0,
						autoplay : 1
					}
				},
				{ version: 9 }
			);
			$('.flash-replaced div.alt').hide();
		} else {
			container = '<img class="modalImg" src="' + srcFile + '" />';
			
			 $.modal(container + '<p>' + proInfo.html() + '</p>', {
			 	onOpen: modalOpen,
				containerCss: {
					width: modWidth
				}
			});
		}
			

        return false;
    });
	
});