/* Author: Richard Peng

*/

$(window).load(function() {
	$('#slides').initSlider();
});

mobilewidth = 480;
tabletwidth = 860;
imgroot = 'http://ad-mays.com/wp-content/themes/mays/img/slider/';
roots = [imgroot+'mobile/',imgroot+'tablet/',imgroot+'wide/']
slideimages = ['webdesign.jpg',
			'graphicdesign.jpg',
			'socialmedia.jpg',
			'contentmanagement.jpg',
			'videoandflash.jpg',
			'seo.jpg',
			'onlinemarketing.jpg'
			];
slideurls = ['http://ad-mays.com/website-design/',
			'http://ad-mays.com/portfolio/',
			'http://ad-mays.com/social-network-marketing/',
			'http://ad-mays.com/website-design/dynamic-website-platforms/',
			'#',
			'http://ad-mays.com/search-engine-optimization-seo/',
			'http://ad-mays.com/online-services/']
state = wide = 0;

$.fn.initSlider = function() {
	width = $(window).width();
	var slides = new Array();
	if (width < mobilewidth) {
		$(this).addimg(0);
		state = wide = 0;
	}
	else if (width < tabletwidth) {
		$(this).addimg(1);
		state = wide = 1;
	}
	else {
		$(this).addimg(2);
		state = wide = 2;
	}
	checkHeight();
}

function checkHeight() {
	if ($('img', '#slides').eq(0).height() == 0) {
		setTimeout(checkHeight,1000);
	}
	else {
		$('.blueberry').blueberry({
			hoverpause: true,
		});
	}
}

$.fn.addimg = function(mode) {
	var slider = this;
	var parent = $(slider).parent();
	$(slider).detach;
	$(slideimages).each(function(i){
		$('<li/>').append($('<a/>', {
			href: slideurls[i]
			}).append($('<img/>', {
				src: roots[mode]+this
		}))).appendTo(slider);
	});
	$(slider).appendTo(parent);
}

// Highslide config
	hs.graphicsDir = 'http://ad-mays.com/wp-content/themes/mays/highslide/graphics/';
	hs.align = 'center';
	hs.allowMultipleInstances = false;
	hs.allowWidthReduction = true;
	hs.dimmingOpacity = 0.8;
	hs.dimmingGeckoFix = true;
	hs.showCredits = false;
	hs.skin.contentWrapper = '<div class="highslide-body"></div>';

function playYoutube(obj){
  if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) 
  {
    hs.htmlExpand(obj, { objectType: 'iframe', 
                         width: 480, 
                         height: 385,
                         allowSizeReduction: false, 
                         //preserveContent: false, 
                         objectLoadTime: 'after',
                        });
    return false;
  }
}

