jQuery.fn.iflip = function( a, b ) {
	
	jQuery(this).click(function() {		
		curr = jQuery(this).find('img').attr('src');
	
		if( curr == a ) {
			jQuery(this).find('img').attr('src', b);
		} else if( curr == b ) {
			jQuery(this).find('img').attr('src', a);
		}
		
	});
	
}
function genQ(m, w, h) {
	var o = '<object width="' + w + '" height="' + h + '" id="quicktimevideo" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B">';
	o += '<param value="' + m + '" name="src"/>';
	o += '<param value="FALSE" name="controller"/>';
	o += '<param value="myself" name="target"/>';
	o += '<param value="video/quicktime" name="type"/>';
	o += '<embed src="' + m + '" width="' + w + '" height="' + h + '" showlogo="true" type="video/quicktime" target="myself" autoplay="true" loop="true" controller="false" pluginspage="http://www.apple.com/quicktime/download/">';
	o += '</object>';
	return o;
}
function loadImage(i, id, l, mId) {
	var p = jQuery('#poster' + i);
	var g = jQuery('#gallery' + i);
	var d = jQuery('#description' + i);
	var a = jQuery('#abstract' + i);
	var sliderPane = jQuery('#slider' + mId);
	
	p.find('a').attr('href', cP + iD + id + fS);
	p.find('img').attr('src', cP + iD + id + pS); 
	jQuery.ajax({
		type: 'GET',
		async: false,
		cache: false,
		dataType: 'json',
		data: {
			imageId: id
		},
		url: iU,
		success: function(da) {
			p.find('#quicktimevideo').remove();
			p.find('img').show();
			a.html(da.text);
			var ptI = sliderPane.find("img.loaded");
			if (ptI) {
				ptI.removeClass("loaded");
				var temp = ptI.attr('src');
				ptI.attr('src', ptI.attr('lowsrc'));
				ptI.attr('lowsrc', temp);
			}
			var tI = sliderPane.find("img." + id);
			var temp = tI.attr('src');
			tI.attr('src', tI.attr('lowsrc'));
			tI.attr('lowsrc', temp);
			tI.addClass('loaded');
			//p.find('a').attr('title', da.text);
			//p.find('img').attr('alt', da.text);
			if (da.mediaurl.length > 0) {
				var w = 320;
				var h = 240;
				p.find('a').attr('href', da.mediaurl);
				if (da.mediaurl.toLowerCase().indexOf('.mov') > -1) {
					p.find('img').hide();
					p.prepend(genQ(da.mediaurl, w, h));
				}
			}
		}
	});
	if (l) {
		a.addClass('abstractLandscape');
		d.addClass('descriptionLandscape');
		g.addClass('galleryLandscape');
		p.addClass('posterLandscape');
	} else {
		a.removeClass('abstractLandscape');
		d.removeClass('descriptionLandscape');
		g.removeClass('galleryLandscape');
		p.removeClass('posterLandscape');
	}
}

jQuery(document).ready(function() {
	if (cId) {
		jQuery('div#categories a[@href*="categoryId=' + cId + '"]').attr('class', 'fat');
	}
	if (fId) {
		jQuery('div#filter a[@href*="filterId=' + fId + '"]').attr('class', 'fat');
	}
	if (l) {
		jQuery('div#i8n a[@href*="request_locale=' + l + '"]').attr('class', 'fat');
	}
	if (jQuery.browser.safari) {
		//jQuery('.sform').html('<input type="text" name="q" accesskey="s" tabindex="0" value="' + q + '" style="background:#666;-webkit-border-radius: 9px 9px;" />')
		jQuery('.sform').html('<span class="left"></span><input name="q" type="text" class="middle" accesskey="s" tabindex="0" value="' + q + '" style="-webkit-appearance: none;-webkit-background-clip: border;-webkit-background-origin: padding;-webkit-rtl-ordering: logical;-webkit-user-select: text;outline-style: auto;outline-width: 0px" /><span class="right"></span>')
	} else {
		jQuery('.sform').html('<span class="left"></span><input name="q" type="text" class="middle" accesskey="s" tabindex="0" value="' + q + '" /><span class="right"></span>')
	}
	jQuery(".lightbox").lightbox();
	jQuery('.previewcontroller').iflip( 'img/delta_closed.gif', 'img/delta_opened.gif');
	jQuery("div.slider").codaSlider();
})
