var FOURSTAR={};
FOURSTAR.menu = [{title:"Home", url:"http://fourstarstudios.com/"}, {title:"Blog", url:"http://blog.fourstarstudios.com"}, /* {title:"Digital", url:"http://fourstarstudios.com/digital.html"}, {title:"Web Comics", url:"http://fourstarstudios.com/webcomics.html", halfagain:true}, */ {title:"Store", url:"http://fourstarstudios.com/store.html"}, {title:"DoubleFeature", url:"http://doublefeaturecomics.com/", doublesize:true} ];

FOURSTAR.teasers = [
  {type:"doublefeature", url:"http://doublefeaturecomics.com", title:"DOUBLEFEATURE", subtitle:"Digital shorts, two at a time."},
  {type:"andthankyou", url:"http://www.andthankyouforflying.com/shop/", title:"and thank you...", subtitle:"Prints by Sean Dove."}, 
//  {type:"sketchbook1", url:"http://fourstarstudios.com/store.html?c=sketchbooks", title:"SKETCHBOOK:1", subtitle:"70 Pages of Seeley Sketches."},
  {type:"battlepug", url:"http://battlepug.com", title:"BATTLEPUG", subtitle:"An epic tale of blood and drool!"},
  {type:"verum", url:"http://city.ofsand.com", title:"CITY OF SAND", subtitle:"Ancient city, unforgettable adventure."}
];

FOURSTAR.bigFour = [
  {type:"andthankyou", url:"http://www.andthankyouforflying.com/shop/", title:"and thank you...", subtitle:"Prints by Sean Dove."}, 
  {type:"sketchbook1", url:"http://fourstarstudios.com/store.html?c=sketchbooks", title:"SKETCHBOOK:1", subtitle:"70 Pages of Seeley Sketches."},
  {type:"battlepug", url:"http://battlepug.com", title:"BATTLEPUG", subtitle:"An epic tale of blood and drool!"},
  {type:"verum", url:"http://city.ofsand.com", title:"CITY OF SAND", subtitle:"Ancient city, unforgettable adventure."},
  {type:"doublefeature", url:"http://doublefeaturecomics.com", title:"DOUBLEFEATURE", subtitle:"Digital shorts, two at a time."}
]


$(function(){
  $('.primary').add($('.secondary')).click(bigFourClicked );
});


function menuWidget(){
  var count = 0;
  var code = "";
  $.each(FOURSTAR.menu, function(c, it){
    count++;
    if(it.halfagain) count+=0.5;
    if(it.doublesize) count++;
    code += '\t<a href="' + it.url + '" class="button '+ (it.doublesize ? 'doublesize ' : '') + (it.halfagain ? 'halfagain ' : '') + (document.title.match(it.title) ? ' selected' : '') +'">'+ it.title + '</a>\n';
  });
  code += '</div>\n';

  count = parseInt(count);
  code = '<div class="menu prefix_' + (11-count) + ' grid_' + count + '">\n' + code;
	
	document.write(code);
}


function bigFourClicked(){
  var title= $('h1', this).html();
  var url = null;
  $.each(FOURSTAR.bigFour, function(c,it){
    if(it.title == title){
      url = it.url;
      return false;
    }
  });
  document.location = url;
}


function bigFourWidget(){
  var it = shuffle(FOURSTAR.bigFour);
  
  var code = '<div class="grid_12"><div class="primary rounded bottom_lead ' + it[0].type + '">';
  code += '<div class="caption grid_6 alpha omega half_bottom_pad half_top_pad"><h1>' + it[0].title + '</h1>';
	code +=	'<p>' + it[0].subtitle + '</p></div></div></div><div class="clear"></div>';

  code += '<div class="grid_4"><div class="secondary rounded '+ it[1].type +'"><div class="caption rounded"><h1>' + it[1].title +'</h1><p>' + it[1].subtitle + '</p></div></div></div>';
  code += '<div class="grid_4"><div class="secondary rounded '+ it[2].type +'"><div class="caption rounded"><h1>' + it[2].title +'</h1><p>' + it[2].subtitle + '</p></div></div></div>';
  code += '<div class="grid_4"><div class="secondary rounded '+ it[3].type +'"><div class="caption rounded"><h1>' + it[3].title +'</h1><p>' + it[3].subtitle + '</p></div></div></div>';
	code += '<div class="clear"></div>';
	
  document.write(code);
}


function teaserWidget(){
  var code = "";
  $.each(FOURSTAR.teasers, function(c, it){
    code += '<div class="grid_3">\n\t<div class="teaser rounded '+ it.type +'" onclick="document.location=\''+ it.url +'\'">\n';
    if(it.title){
      code += '\t\t<div class="caption rounded">\n\t\t\t<h1>' + it.title + '</h1>\n\t\t\t<p>' + it.subtitle + '</p>\n\t\t</div>\n';
    }
    code += '\t</div>\n</div>\n';
  });
  document.write(code);	
}



function preload(arrayOfImages) {
  $(arrayOfImages).each(function(){
    $('<img/>')[0].src = this;
  });
}


function bigcartelStore(){
  var html = '<iframe src="http://fourstarstudios.bigcartel.com/';
  var query = window.location.search.substring(1).split("=");
  if(query[0] == "c"){
    html += 'category/';
    html += query[1];
  }else{
    html += 'products';
  }
  html += '" scrolling="no" frameborder="0" width="700" height="1024"></iframe>';
  document.write(html);
}


function shuffle(array) {
    var tmp, current, top = array.length;

    if(top) while(--top) {
        current = Math.floor(Math.random() * (top + 1));
        tmp = array[current];
        array[current] = array[top];
        array[top] = tmp;
    }

    return array;
}
