Cufon.replace('h2, h3, .main_image h1', {
	fontFamily : 'archer'
});
Cufon.replace('.archer_medium, .blue_button, .button', {
	fontFamily : 'archer medium'
});
Cufon.replace('.archer_bold, .device_list', {
	fontFamily : 'archer bold'
});
$(document).ready(function() {
	deviceSelector.init();
	// $('.favourites_link').attr('href', 'javascript: void(0);');
		// $('.favourites_link')
		// .click(
		// function() {
		// var $favLink = $('.favourites_link');
		// if ($favLink.attr('curState') == 1) {
		// var state = 0;
		// } else {
		// var state = 1;
		// }
		// Cufon.replace('.favourites_link', {
		// fontFamily : 'archer medium'
		// });
		//
		// $
		// .ajax( {
		// type : 'get',
		// url : "?&op=fav&SkinID="
		// + $favLink
		// .attr('skinID')
		// + "&favStatus="
		// + state,
		// success : function(x) {
		// if (state == 1) {
		// $favLink
		// .css(
		// 'background',
		// 'url("/resources/images/icons/favourite_remove.gif") no-repeat scroll
		// 0
		// center transparent');
		// $favLink
		// .removeClass('favourite_add');
		// $favLink
		// .addClass('favourite_remove');
		// $favLink
		// .html('Remove from favorites');
		// $favLink
		// .attr(
		// 'title',
		// 'Remove from favorites');
		// } else {
		// $favLink
		// .css(
		// 'background',
		// 'url("/resources/images/icons/favourite_add.gif") no-repeat scroll 0
		// center
		// transparent');
		// $favLink
		// .removeClass('favourite_remove');
		// $favLink
		// .addClass('favourite_add');
		// $favLink
		// .html('Add to favorites');
		// $favLink
		// .attr(
		// 'title',
		// 'Add to favorites');
		// }
		// $favLink.attr(
		// 'curState',
		// state);
		//
		// Cufon.now();
		// }
		// });
		// });
	});

/*
 * Device Selector
 * --------------------------------------------------------------------------
 */
// used on image details page.
var deviceSelector = {
	currList : null,
	currLink : null,
	scrollbarWidth : 15,

	init : function() {
		// initialize custom overflow scrollers
	$('.device_sublist').jScrollPane( {
		scrollbarWidth : deviceSelector.scrollbarWidth
	});
	$('.device_sublists').css('visibility', 'visible');

	// find the initial active items and display it's list
	deviceSelector.currList = $('.device_sublist.active');
	deviceSelector.currLink = $('#device_selector .active');
	deviceSelector.currList.parent().css('visibility', 'visible');

	// event listener for device category links
	$('#device_selector a').click(function() {
		var linkID = this.id;
		var listID = linkID + '_list';
		var list = $('#' + listID);

		// change active category link
			deviceSelector.currLink.removeClass('active');
			$(this).parent().addClass('active');
			deviceSelector.currLink = $(this).parent();

			// hide old list, show new list
			deviceSelector.currList.parent().css('visibility', 'hidden');
			list.parent().css('visibility', 'visible');
			deviceSelector.currList = list;

			return false;
		});
	// event listener for device links
	$('.device_sublist a').click(function() {
		deviceSelector.loadDevice($(this).attr('furl'), this.id);
		return false;
	});

},

loadDevice : function(deviceID, cssID) {
	// change the current active device
	var currActive = $('#' + cssID).parent().parent().find('.active');
	currActive.removeClass('active');
	$('#' + cssID).parent().addClass('active');
	// show the loading gif
	$('#device_details').css('display', 'none');
	$('#device_loading').css('display', 'block');
	$('#skinView').html($('#loaderView').html());
	// send the ajax request See http://api.jquery.com/jQuery.ajax/ for more
	// details
	$
			.ajax( {
				type : "GET",
				url : "?deviceID=" + deviceID + "&blockID=deviceSelectors",
				// data: "deviceID="+deviceID,
				dataType : 'json',

				success : function(returnedJSON) {
					ajaxUpdate(returnedJSON);

					// replace cufon text on new html
					Cufon.replace('h3', {
						fontFamily : 'archer'
					});
					Cufon.replace('.blue_button', {
						fontFamily : 'archer medium'
					});

					// hide the loading gif
					$('#device_details').css('display', 'block');
					$('#device_loading').css('display', 'none');
				},

				error : function(XHR, msg, error) {
					alert('There was a problem communicating with the server, please try again.');
				}
			});
}
}
